开发者

Client ip address using javascript

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.S开发者_运维知识库SI already enabled.Please help me....Thanks


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜