Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

How to get you Extenal/Real IP (Router)

Thread view: 
Homer - 17 Apr 2006 19:36 GMT
Hi All,

I am writing a code as a Java Application (not Applet or Servlet) and I
am trying to find out what is my real IP address (not 192.168. one). I
am behind my LinkSys router and everything I try I still get 192.168.

I have tried:
- InetAddress: Always returns 192.168 address (unless I am missing
something).
- Open Socket to www.cnn.com,80 and read local address (still 192.168).
- I am reading about Upnp but not sure if that's the way I can ask my
Router about my real IP.
- Calling http://www.whatismyip.com and parse the result seems too
strange.

Any idea?

Thanks in advance,

Homer
Thomas Hawtin - 17 Apr 2006 18:59 GMT
> I am writing a code as a Java Application (not Applet or Servlet) and I
> am trying to find out what is my real IP address (not 192.168. one). I
> am behind my LinkSys router and everything I try I still get 192.168.

The 192.168.. address is the real IP address of your machine. To get the
 IP address of the other side of your NAT router will be router
dependent. For my D-Link router, I'd have to login to the administration
pages and find the IP address amongst the JavaScript.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Roedy Green - 18 Apr 2006 00:24 GMT
On Mon, 17 Apr 2006 18:59:22 +0100, Thomas Hawtin
<usenet@tackline.plus.com> wrote, quoted or indirectly quoted someone
who said :

>  IP address of the other side of your NAT router will be router
>dependent.

I call that the FACE IP.  To determine it, see
http://mindprod.com/jgloss/ip.html

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

James McGill - 17 Apr 2006 19:52 GMT
> - Calling http://www.whatismyip.com and parse the result seems too
> strange.

You can't do it reliably without querying some service that can see the
remote address of the connection, and that means something outside your
gateway.  That's why webservices like that are needed, otherwise the
browser would be able to give you the info.

Why do you need the "real" address?  If it's not something you can put
in DNS (and reverse DNS), how do you know it won't change between calls
to your function?
Philipp Leitner - 17 Apr 2006 20:36 GMT
> - Calling http://www.whatismyip.com and parse the result seems too
> strange.

Why's that so bad? Using a Web Service seems to be a good way to solve
your problem - just make sure that you can exchange the service easily
if it is removed for one reason or another.

/philipp
Homer - 17 Apr 2006 20:56 GMT
To answer to question "why do I need external IP address?":

I have a website hosted somewhere for a little bit of money. The
problem is that hosting company doesn't support PHP, MySql,.... (that
I need for my FamilyTree software)
I have DSL connection as home and I put some small html pages on
hosting site to forward all Not-Supported requests to my home web
server.
Inside those small-html-files I have my dynamic home ip address and I
need to change it whenever my ip address changes.

Now I wrote some code (working great): It runs as service
(wrapper.tanukisoftware.org) and checks my external IP address every 5
second (I am sending httpRequest to http://www.whatismyip.com and parse
the response until I find a better solution). Then it pulls (ftp) my
html files from hosting site, put the new IP and push them back into
the site.

I know that it looks a bit ugly, but it's free and it's working
(with up to 5 sec delay).
Oliver Wong - 17 Apr 2006 20:59 GMT
> To answer to question "why do I need external IP address?":
>
[quoted text clipped - 16 lines]
> I know that it looks a bit ugly, but it's free and it's working
> (with up to 5 sec delay).

   Have you considered using a service like no-ip.com?

   - Oliver
Homer - 17 Apr 2006 21:26 GMT
Nope. I know it's cheap but is not free.
And my code is working. I just want to make it better. I can even put
some code in my Hosting server to return my IP address instead of using
whatismyip.com.
Oliver Wong - 17 Apr 2006 22:13 GMT
> Nope. I know it's cheap but is not free.
> And my code is working. I just want to make it better. I can even put
> some code in my Hosting server to return my IP address instead of using
> whatismyip.com.

   no-ip.com provides different services. The so called "Free" service is
free. See http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html

   On the other hand, the "Free" service is intended for "personal use
only". Not sure how that fits in with your site (which I believe you
mentioned makes a bit of money). You might want to read the contract
carefully to see what is or isn't allowed.

   I used to use the free service, but eventually I just bought a domain
name and a static IP.

   - Oliver
Roedy Green - 18 Apr 2006 00:24 GMT
>    On the other hand, the "Free" service is intended for "personal use
>only". Not sure how that fits in with your site (which I believe you
>mentioned makes a bit of money). You might want to read the contract
>carefully to see what is or isn't allowed.

there are a number of other such services.  Check them out via
http://mindprod.com/jgloss/dyndns.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Alex Hunsley - 17 Apr 2006 23:54 GMT
> Nope. I know it's cheap but is not free.

No-ip.com is free, I've been using it at work for ages and it's still free.
Also dyndns.org is free. I actually recommend dyndns.org, because they
provide you with a free download called noipDuc (or similar) that runs
on your machine and updates their DNS servers whenever your external IP
changes.

Also, my wireless router (Linksys WRT54G) has a feature in the admin web
pages to allow auto updating of your dyndns address, so I don't even
have to run noipDuc on my desktop machine any more.

> And my code is working. I just want to make it better. I can even put
> some code in my Hosting server to return my IP address instead of using
> whatismyip.com.

I'd seriously avoid doing this in your own code - I appreciate it works,
but it seems inelegant, when dyndns.org works so well and is free.
Amfur Kilnem - 18 Apr 2006 00:16 GMT
> Nope. I know it's cheap but is not free.
> And my code is working. I just want to make it better. I can even put
> some code in my Hosting server to return my IP address instead of using
> whatismyip.com.

I have created another solution that works pretty well, and it is entirely
self-contained (ie, no third-party software or fees).

I have a small program running on my home server (Sun Netra).  It's actually
two threads: one is a mini-server, which listens on a local port; the other
will access that port every few minutes, at my last known IP address, asking
for a magic number.  If the magic number is wrong, or there's no response
from the mini-server, then the IP must have changed, so the program will
then access a CGI script on my remote (paid-for) website.  That CGI script
will extract my home IP from the request header, and save it to a file.  It
will also return the IP address back to my home server, where it will be
saved to my "last known IP" file.  So now my home IP is saved at both ends.

It gets better.  I have another CGI script on my remote web-site, which acts
as another mini-server.  When this one is accessed, it will open a
connection to my home server (it has the IP address, remember!), and will
pass the query portion of the request to the home server, where it will be
passed to Tomcat, which creates HTML from a mixture of JSP and Servlets.
And because the home server also knows the home IP, it can plug that IP
address into the newly-created pages.  What this means in practice is that I
can create content which contains references to images (for example) that
are on my home machine.  The address bar in the browser still points at my
remote website, while some (or all) of the content is here at home.  And
even if my IP changes, the generated pages will always contain the correct
IP.
Homer - 18 Apr 2006 13:42 GMT
Very cool. nice work (what do you think about my solution?).
I beleive those free services (like noip, dynip,..) are a bit slow
since it will take some time to update DNS servers everywhere.
Homer - 18 Apr 2006 13:55 GMT
BTW. I can use this to return my IP: (just save it to something.cgi and
call it)

#!/usr/bin/perl

use warnings;
use strict;

use CGI qw/:standard/;

my $remote_ip = $ENV{'REMOTE_ADDR'};

print header;
print "Your IP is: $remote_ip\n";
Amfur Kilnem - 18 Apr 2006 15:06 GMT
> Very cool. nice work (what do you think about my solution?).

I had tried the same thing, but accessing my remote server every few seconds
was generating huge log files.

My method generates no log files, and no internet traffic, until the IP
changes.
David Segall - 18 Apr 2006 07:32 GMT
>Now I wrote some code (working great): It runs as service
>(wrapper.tanukisoftware.org) and checks my external IP address every 5
>second (I am sending httpRequest to http://www.whatismyip.com and parse
>the response until I find a better solution). Then it pulls (ftp) my
>html files from hosting site, put the new IP and push them back into
>the site.
I like it! I do it the other way round by using my Dlink 624-S to
monitor the IP address and let ZoneEdit know if it changes. That part
is free but I pay an insignificant $11.00/year to have ZoneEdit
monitor my web site and switch over to my free ISP site if my server
is unreachable. I think your method is better because I could direct
all the plain HTML requests to my ISP making them faster and more
reliable and only redirect the stuff I cannot host there.

Would you mind sharing your code? If that's OK, perhaps you could send
it to david at segall dot net. The "Reply To" address is invalid.  
Martin Gregorie - 17 Apr 2006 20:44 GMT
> Hi All,
>
> I am writing a code as a Java Application (not Applet or Servlet) and I
> am trying to find out what is my real IP address (not 192.168. one). I
> am behind my LinkSys router and everything I try I still get 192.168.

Visit grc.com or crypto.yashy.com/nmap.php - both are web sites and will
report your firewall's external IP.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Homer - 18 Apr 2006 15:03 GMT
As an update: I put a small thread inside my code (I didn't want to run
another code) to listen to some port (socket accept) and also I added a
open socket line to my code (as a client). So I am checking everything
inside one peace of code. Everything is cool now. Thanks to Amfur for
his idea.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.