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

1

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@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?
I got the answer what i need. stackoverflow.com/questions/391979/… Thank you so much
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).

1 Comment

Thank you.Absolutely right you are....Now i got an idea and i get the answer what i need.Thanks again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.