0

I need to getting the client ip address using javascript.Actually,our connection provider ip is something like this 122.172.127.200.We are putting different private ip like 192.168.10.1,192.168.10.2 and so on..i can retrieve 192.168.10.1,but how can i retrieve the 122.172.127.200 using php or javascript.SSI already enabled.Please help me....Thanks

Aadi
  • 6,959
  • 28
  • 100
  • 145

2 Answers2

4

I'm not entirely sure whether I understand your situation, but in PHP it's easy:

echo $_SERVER["REMOTE_ADDR"];

in Javascript, it's not possible without some server-side interaction. Related question here

If that doesn't address your problem, please clarify your question a bit.

Update: If you are operating completely within your local network, and need to find out your public IP address provided by the ISP, you would have to either query your DSL router (or whatever device connects you to the internet) or (much much easier) this:

  • make an Ajax call to a PHP script outside your local network (= on the public internet)
  • Have that PHP script contain <? echo $_SERVER["REMOTE_ADDR"]; ?>
  • Your Ajax call will get back your public IP address.

You need external hosting for this solution but as far as I can see, it is the easiest for that scenario.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • @Ajith please clarify your question. It's impossible to understand your network setup from your description. Whose IP is that? What are the local IPs? Who is server, who is client? – Pekka Apr 10 '10 at 10:18
  • I got the answer what i need. http://stackoverflow.com/questions/391979/get-client-ip-using-just-javascript Thank you so much – Aadi Apr 10 '10 at 10:25
0

You can't without JavaScript on it's own. But as Pekka, you can get it from any server-side script (which actually can write it into the JavaScript before it's sent to the client). You can also get it via Ajax (xhr if it's on you domain or DSL if you find a service providing IPs in JSON format).

xavierm02
  • 8,457
  • 1
  • 20
  • 24
  • Thank you.Absolutely right you are....Now i got an idea and i get the answer what i need.Thanks again – Aadi Apr 10 '10 at 10:24