I want to have the internal IP address of my LAN using simple javascript approach.
Without using any third party service.
I want to have the internal IP address of my LAN using simple javascript approach.
Without using any third party service.
There's no way to get your IP address with Javascript only. You'll need to rely on a third party service (or retrieve your IP with on your server and return it in the view where your js code is printed).
There's no notion of hosts or ip-addresses in the javascript standard library. So you'll have to access some external service to look up hostnames for you. I recommend hosting a cgi-bin which looks up the ip-address of a hostname and access that via javascript.
If you want to use ONLY JavaScript and if it's not a problem to do that not browser-side only, you can use NodeJS and Express Framework to make a "micro-web app" which do something like :
app.get('/', function (req, res) {
var hey = request.connection.remoteAddress;
});
In addition, you can also retrieve a client IP even if it is behind a proxy with :
request.headers['x-forwarded-for']
Interesting link on SO about that here
Maybe it's a bit overkill... Depending of what you wanna do.