2

I want to obtain the remote client ip by javascript, not querying any external ip resource pools. how could i get the remote ip address, just like the way i get appName by navigator.appName

also like the ways as follows:

PHP:<?php echo $_SERVER["REMOTE_ADDR"]; ?>

NODE.JS: req.connection.remoteAddress

so green with javascript, and im trying to google with some keywords. yet i still can't find the result i want. any guy here could share his solution of the same desired scene? any tips or suggestions are welcome.

platform:chrome, firefox

2
  • possible duplicate of Get Client IP using just Javascript? Commented Apr 19, 2013 at 14:44
  • yeap, the same problem(i had read it). but so pity the answers cannot help yet. thanks @Ian. Commented Apr 19, 2013 at 14:54

2 Answers 2

3

You can't know it on the client because the client doesn't know it. For example, if the client is behind a NAT, the IP of the machine will be different from the IP the "world" sees.

Make a simple server (AJAX) call that will return you the remote address.

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

3 Comments

what i need just like noedejs, calling the api: req.connection.remoteAddress. When the browser open a web, the browser get the remote client's info, including the client ip? my question is, is there any way to get the remote ip like i getting navigator.appName, not by any response server? maybe there is some shared infos or envirments betwen the browser and javascript runtime environment, and then i could get the ip by some api? im not sure.
For the browser, it's not remote, it's local. The browser runs on the clients machine, and the client's OS might not know what it the IP it's visible to the outside world. TL;DR - You need a server call, only client-side javascript will not work.
Thank Emil's reply. I see what you mean, but yet a related problem make me puzzled me, that is, when opening a page with js, is there some relationship or mapping between the local ip and the connection to the the page (could we looks as remote server's reponse, like some resource file deriving from remote server?). If so, there should will be an api to get the local ip address. //maybe im wrong.I need some more related knowledge in depth.
3

This is not possible using pure Javascript without external calls.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.