How to find the internal IP?

Asked

Viewed 4,238 times

4

I’m looking for a solution to know the ip engine.

The idea is that through a website, when the user accesses it, know which the ip inside of him, and then looking for everyone else ip's, and find the machine that has an installed application.

So far manage to do this with Rtcpeerconnection but does not work on all browsers.

  • I think I missed something. Rtcpeerconnection is a solution for browsers, isn’t it? But you say the application has to be installed? What kind of technology/installation do you really have? Because if it were a desktop program installation, it would be very easy to get the real IP from the machine.

  • hello I think I explained wrong, in the client will have a machine with a server, that will authenticate with the site. the idea is to do something like Chromecast, so I call on a site that is ready for Chromecast it shows an icon

  • 1

    I can’t help you with your javascript solution, but just contextualize it: it doesn’t exist or I don’t understand what "internal IP" might be. Generally a computer can have no or multiple network interfaces with an IP configured on each one. For example: you can have three interfaces: wlan, ethernet and loopback. So you can have three recognizable and usable IP addresses (however for different routes/purposes). What do you mean by "Internal IP"?

  • ex: the chormecast, can know what is its IP(internal ip: 192.168.2.110 ; its external ip: 88.888.8.88), ok? if I have Chromecast installed in my network, when I enter a site that is compatible with it, automatically appears an icon that I can see the content of the site in my Chromecast. my idea is to do something similar. ex: is this site (http://net.ipcalf.com/) it shows your internal ip, the ip of your machine

  • Got it. Well, I think it makes no sense for you to talk about "internal IP" and "external IP" because in many cases they will be the same. Conceptually IP is IP. As for javascript, as I said, I can’t help. But I particularly doubt that the discovery of Chromecast on the network is made by a javascript in the browser that scans the network interfaces every time you enter a site enabled for this.

  • OK Francisco thanks I will research more on the subject.

Show 1 more comment

3 answers

3

An answer to this was posted on Stackoverflow in English by the user nodyou: https://stackoverflow.com/questions/3653065/get-local-ip-address-in-node-js

var os=require('os');
var ifaces=os.networkInterfaces();
for (var dev in ifaces) {
  var alias=0;
  ifaces[dev].forEach(function(details){
    if (details.family=='IPv4') {
      console.log(dev+(alias?':'+alias:''),details.address);
      ++alias;
    }
  });
}

If further details are required, the documentation is at http://nodejs.org/api/os.html#os_os_networkinterfaces

  • woliveirajr, thank you, I’ll see to that.

0

Michel Melo says that his client will have "a machine with a server". In this case, it means that, for example, has a WAMP or a MAMP on the machine. Using this server, locally the client will put data, using client software (for example Firefox) Exemple: Main site with Linux is a web server Local website with WAMP Client using Firefox on WAMP

Michel’s problem does not seem to be "How will my Linux server know the IP address of Firefox from Usario", because your Linux won’t connect to Linux. Michel’s problem is "How can my Linux server know the IP of the WAMP server that will connect". And that?

If so, the answer cannot be "Use JS" because WAMP will not use JS.

The other problem is that if the client’s internet connection is disturbed, your local network may receive another IP address. And in this case, the client’s "server" will not be recognized by the "global server"".

Analyzing this, I think the best option is to transmit on the served site a connection code. And each time this local server will connect to the "global" server, it will transmit the code. IP does not seem to me a reliable or sufficient option.

  • Here is different from a forum, the questions and answers should shine by themselves, so we do not send greetings in the posts. You do not speak Portuguese natively?

0

var object_ip = function(){
    return new Promise( function( resolve, reject ){
        let Ips = {};
        let counter = 1;
        let os=require('os');
        let ifaces=os.networkInterfaces();
        for( let i = 0; i < Object.keys(ifaces).length; i++){
            ifaces[Object.keys(ifaces)[i]].forEach(el=>{
                if(!!el.address){
                    Ips['Ipv'+counter.toString()] = el.address;
                    counter++;
                }
            })
        }

        if(!!Object.keys(Ips).length){
            resolve(Ips);
        }else{
            reject("Dont Have IP");
        }
    })
}

object_ip()

    .then( function(result){ 
        console.log(result); 
    })
    .catch( function(error){ 
        console.error(error);
    })
  • Unless mistaken, this code is only for Node JS, right? How would you apply on a site as requested in the question?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.