My Address Java Applet

If you want the IP Address of a visitor to be shown on a webpage, download MyAddress.class, store it in the same folder as your html file and simply include the line:
<APPLET CODE="MyAddress.class" WIDTH=500 HEIGHT=14>Sorry, Java is diabled</APPLET>
Which results in:

Sorry, Java is disabled

Advanced Features

MyAddress.class Version 1.3 understands the following parameters:

BGCOLOR

The background color of the applet. Currently only BLACK and WHITE (default) are supported.
<APPLET CODE="MyAddress.class" WIDTH=500 HEIGHT=14>
<PARAM NAME="BGCOLOR" VALUE="BLACK">
</APPLET>
results in:

TEXT

Text displayed in front of the address.
<APPLET CODE="MyAddress.class" WIDTH=500 HEIGHT=14>
<PARAM NAME="TEXT" VALUE="Your current IP is: ">
</APPLET>
results in:

URL

The URL parameter tells the applet which url to open with the IP address appended, when the user clicks it.
<APPLET CODE="MyAddress.class" WIDTH=500 HEIGHT=14>
<PARAM NAME="URL" VALUE="demo.html?IP=">
</APPLET>
results in:

This example will open the URL "demo.html?IP=xxx.xxx.xxx.xxx" Useful for cgi scripts which usually can get the IP of a client via the REMOTE_ADDR environment field but if a proxy or firewall is inbetween get a wrong IP. Or the called page uses JavaScript to process the IP locally.

Note: From Version 1.2 on you need to set the ACTION parameter for automatic execution.

ACTION

If you set the ACTION parameter to "AUTO", the URL will open immediately on loading the applet, no user click required.
<APPLET CODE="MyAddress.class" WIDTH=500 HEIGHT=14>
<PARAM NAME="URL" VALUE="demo.html?IP=">
<PARAM NAME="ACTION" VALUE="AUTO">
</APPLET>
Click here to open a page containing this code.
If ACTION is set to an numeric IP address, automatic opening only happens when it matches the local address.

NOACTION

If this tag is defined, the "ACTION AUTO" tag is ignored if the IP equals the NOACTION value. Saves bandwith and server load if the REMOTE_ADDR field known to the server is already correct. The cgi script should simply put the REMOTE_ADDRESS value here. The IP must be specified in numerical notation!
<APPLET CODE="MyAddress.class" WIDTH=500 HEIGHT=14>
<PARAM NAME="URL" VALUE="demo.html?IP=">
<PARAM NAME="NOACTION" VALUE="xxx.xxx.xxx.xxx">
</APPLET>

TARGET

The TARGET parameter specifies the window where to open the URL.
<APPLET CODE="MyAddress.class" WIDTH=500 HEIGHT=14>
<PARAM NAME="URL" VALUE="demo.html?IP=">
<PARAM NAME="ACTION" VALUE="AUTO">
<PARAM NAME="TARGET" VALUE="_new">
</APPLET>
Click here to open a page containing this code.

A special meaning has a TARGET value of "_STEALTH". The URL is requested but not displayed! Useful only with some cgi script...

<APPLET CODE="MyAddress.class" WIDTH=500 HEIGHT=14>
<PARAM NAME="URL" VALUE="demo.html?IP=">
<PARAM NAME="TARGET" VALUE="_STEALTH">
</APPLET>

LOOKUP

By default MyAddress displays the IP Address numerically. When LOOKUP is set to YES, it tries to resolve the IP to it's DNS name. However, this is not possible in most cases due to the security settings of the Java VM. Querying a DNS server is regarded as "leaving the sandbox".
<APPLET CODE="MyAddress.class" WIDTH=500 HEIGHT=14>
<PARAM NAME="LOOKUP" VALUE="YES">
</APPLET>
results in:

STATUS

If there is no URL specified, MyAddress.class advertises itself in the status line of the browser. If you don't like this, you can use the STATUS parameter. However, the copyright is always displayed when the user clicks on the applet.
<APPLET CODE="MyAddress.class" WIDTH=500 HEIGHT=14>
<PARAM NAME="STATUS" VALUE="Hello from MyAddress Applet">
</APPLET>
results in:

Interfacing with JavaScript

Many people want to use the local IP in some JavaScript. There is no direct way to access it. This applet provides 3 different methods to pass the IP to JavaScript.

A) The Applet calls JavaScript

If you put the MAYSCRIPT tag in the applet declaration, MyAddress.class will try to call the Javascript function MyAddress(IP) which you have to define somewhere in the document. It is called, when the applet initializes.
<script>
function MyAddress(IP) { alert("Your local IP is " + IP) } 
</script>
<APPLET CODE="MyAddress.class" MAYSCRIPT WIDTH=0 HEIGHT=0></APPLET>
If you want to specify a different function name you can use the CALL parameter
<PARAM NAME="CALL" VALUE="MyJavascriptFunction">
Click Here for a demo page!

B) Calling the Applet from JavaScript

If you name the applet, you can access it's ip() method directly from JavaScript. But this won't always work, as many browsers now by default have access from JavaScript to Java disabled. To be really sure to get the address into JavaScript you should use the former method or use the URL and ACTION parameters.
<BODY onload="document.foo.bar.value=document.xyz.ip()">
<FORM NAME="foo"><INPUT TYPE="text" NAME="bar"></FORM>
<APPLET CODE="MyAddress.class" NAME="xyz" WIDTH=0 HEIGHT=0></APPLET>
Click Here for a demo page!

C) Let the Applet open another page

Use the "URL http://www.yourserver.com/yourpage.html?IP=" and "ACTION AUTO" parameters to open another html page with the IP address as a QUERY_STRING. Note that this will reveal the real loacal address also to the server!
Click here to demonstrate this method.

FAQ

What is this applet good for?

I created this applet for the Music of the Internet project. However I got numerous requests for it, so I post it here. There are several situations where you may need to know your real IP address, especially when you dial-up to the internet and get a different IP every time: Somebody wants to call you with NetMeeting or you run some server software. Other people need your address then to reach you.
If you do not have CGI or ASP capabilities, this applet is your only chance to get access to the IP address of the client! To see an artistic appliction of this applet, please visit the Virtual Velazquez by Stephen E. DeLong!

How to communicate the real IP back to the server?

Let the applet automatically open a cgi script on your server by using the "URL http://www.yourserver.com/yourscript.cgi?IP=" and "ACTION AUTO" parameters. You can then access the IP as QUERY_STRING in that script.

Other IP sites show different addresses for me

Most other IP monitoring sites use a server side cgi script to display the IP of a visitor. If you are behind a firewall, use a proxy or some NAT like ICS they will only know the address of the proxy, firewall or NAT router. This Java applet in contrast get's the IP directly from your computer locally and thus shows it's real IP.
This may be an advantage or not: In case you're just using a proxy, your real address is most meaningful to the outside indeed. But behind a firewall or a NAT router your "real" address cannot be reached from any other computer on the internet.
If this applet shows an IP like 192.168.x.x or 10.0.x.x you are surely within a local network and other people cannot connect to your computer from the outside, except via the address of a router or firewall which is configured to relay some ports to you.
Try this page for a CGI based IP address display or look at the traceroute page from Stanford to see all the long route to you.

It displays the wrong address

If this applet displays an address, it is exactly that local IP address the client uses to connect to the server. However, one computer may have multiple IP addresses. Each network adaptor brings one, 127.0.0.1 is the local loopback address and VPN or special proxy software may install own virtual adaptors. So your address may be different from what you expect.

This applet does not work if loaded from a local disk

Yes, that's true! It must be served by a web-server to work due to Java security!

Do I have to download the Applet or can I simply link to your one?

Please download MyAddress.class (Right-Click, Save As) and save it along with your html file. Some people used to include a reference to the applet on this server, but due to the increasing popularity of this applet this behavoir created a tremendous amount of traffic for me. Also for your own security it is recommended to use your own copy of the applet as I upgrade it from time to time and the interface may change.

Is it free?

Yes. However, it would be nice to give some credits to me and/or link to this page.

Can I get the sourcecode?

Sorry, no.

How can I hide my IP from the websites I surf?

This applet demonstrates that any server you visit can find out your real IP address if you enable Java, even if you're behind a firewall or use a proxy.
If you want some privacy you have to: But no guarantee for this tips at all!
©2003 Lars Kindermann