Is there any way you can find the IP of the server that the browser is connected to? For e.g. if the browser is accessing http://www.google.com, can we tell in any way what IP it is connected to? This is very useful in cases where Round-robin DNS is implemented. So say, the first request to a.com
results in 1.1.1.1
& subsequent request result in 1.1.1.2
& so on.
I couldn't find any way to do it with JavaScript. Is it even possible? If not is there any universal way to find this info out?
For example: json(`https://api.ipdata.co?api-key=${apiKey}&fields=ip`).then(data => { console. log(data. ip); });
php echo "Your IP is"; echo $_SERVER["REMOTE_ADDR"]; function get_ip_address() { // check for shared internet/ISP IP if (! empty($_SERVER['HTTP_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_CLIENT_IP'])) return $_SERVER['HTTP_CLIENT_IP']; // check for IPs passing through proxies if (!
Try this as a shortcut, not as a definitive solution (see comments):
<script type="text/javascript"> var ip = location.host; alert(ip); </script>
This solution cannot work in some scenarios but it can help for quick testing. Regards
Fairly certain this cannot be done. However you could use your preferred server-side language to print the server's IP to the client, and then use it however you like. For example, in PHP:
<script type="text/javascript"> var ip = "<?php echo $_SERVER['SERVER_ADDR']; ?>"; alert(ip); </script>
This depends on your server's security setup though - some may block this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With