How does "What is my Private IP" work?

The "What is my private IP" page uses a Java applet to get your private IP, which then passes it to a PHP script running on our server.

The source of our applet is shown below. Line 31 allows you to set the script that you want to pass the IP address to. In this example, the IP is passed as the GET variable ip.

Simply save the source as ipaddres.java, then compile it (e.g., 'javac ipaddres.java') to create the ipaddres.class file that can be embedded on a website:

/* This code is public domain */
/* Source: http://ipaddr.es */

import java.applet.Applet;
import java.applet.AppletContext;
import java.net.*;
public class ipaddres extends Applet
{
    public ipaddres()
    {
    }

    public void start()
    {
        String s = "unknown";
        String s1 = getDocumentBase().getHost();
        byte byte0 = 80;
        showStatus("(1) Visit http://ipaddr.es");
        try
        {
            String s2 = (new Socket(s1, byte0)).getLocalAddress().getHostAddress();
            if(!s2.equals("255.255.255.255"))
                s = s2;
        }
        catch(Exception exception)
        {
            showStatus("(2) Visit http://ipaddr.es");
        }
        try
        {
            URL url = new URL(getDocumentBase(), "local-ip.php?ip=" + s);
            getAppletContext().showDocument(url, "_self");
        }
        catch(Exception exception1)
        {
            showStatus("(3) Visit http://ipaddr.es");
        }
    }
    String Ip;
}

To embed the applet on your webpage, you can use something like this:

<applet width="1" height="1" code="ipaddres.class" CODEBASE="/"></applet>

Last updated: December 20, 2014 (3:55 PM GMT)