John John - 1 year ago 137
Javascript Question

How to find out the server IP address (using JavaScript) that the browser is connected to?

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, 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
results in
& subsequent request result in
& 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?

Answer Source

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']; ?>";

This depends on your server's security setup though - some may block this.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download