0

My website need to get information about internal IP address of visitor. Then it shows all devices associated with my website in internal LAN (goes from 1-254 ending step by step to identify devices in local network). It was able to identify first three portions (e.g. 192.168.0.x) via WebRTC. But now it is not possible anymore.

Any idea please, how to identify it via web browser on website? (for example with javascript)

peter
  • 4,289
  • 12
  • 44
  • 67
  • 3
    You should elaborate on your **specific use case**. This isn't generally possible. And, in general you shouldn't even assume that this is how the network is set up. – Brad Dec 02 '19 at 18:27
  • Check out https://stackoverflow.com/questions/20194722/can-you-get-a-users-local-lan-ip-address-via-javascript?rq=1 . The first answer shows one means to do this, and discusses the risks of relying on this feature. – Freiheit Dec 02 '19 at 18:29
  • Why isn't it possible anymore? What changed? What about Java applets? – Mr. B. Dec 02 '19 at 18:30
  • @Mr.B. because webrtc leak of IP is fixed in almost all web browsers. So it does not work anymore. – peter Dec 02 '19 at 18:56
  • @Shimmy568 webrtc leak of IP is fixed in almost all web browsers. So it does not work anymore. – peter Dec 02 '19 at 18:58
  • Disabling flags for webrtc in web browsers could be a way - but this is not practicaly possible (user should interact and in fact user will not interact with additional settings) – peter Dec 02 '19 at 18:59
  • What about Java applets? – Mr. B. Dec 02 '19 at 19:21
  • @Mr.B., could you please share Java applet example for this? (ideally workable solution for any web browser on client side) – peter Dec 03 '19 at 07:05
  • I just answered with a Java applet example, but I didn't test it. The source is mentioned at the end. Good luck with it! – Mr. B. Dec 03 '19 at 08:26

1 Answers1

0

Here is an untested Java applet solution that might work:

Socket socket = new Socket(getDocumentBase().getHost(), port);
ip = socket.getLocalAddress().getHostAddress();
package com.mkyong.applet;

import java.applet.*;
import java.awt.Graphics;
import java.io.IOException;
import java.net.Socket;

public class AppletExample extends Applet {

    String ip;

    public void init() {

      try{
        int port;

        if(getDocumentBase().getPort()!=-1){
            port = getDocumentBase().getPort();
        }else{
            port = 80;
        }

            Socket socket = new Socket(getDocumentBase().getHost(), port);
        ip = socket.getLocalAddress().getHostAddress();

            }catch(IOException io){
        System.out.println(io.getMessage());
        }
    }

    public void paint( Graphics g ) {

       StringBuffer sb = new StringBuffer()
        .append(" IP address : ").append(ip);

       g.drawString(sb.toString(), 0,100);
    }

}

It's not my code, please check the source for license.

Mr. B.
  • 8,041
  • 14
  • 67
  • 117