How to get you Extenal/Real IP (Router)  
Author Message
Homer





PostPosted: 2006-4-18 2:37:00 Top

java-programmer, How to get you Extenal/Real IP (Router) 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





PostPosted: 2006-4-18 1:59:00 Top

java-programmer >> How to get you Extenal/Real IP (Router) Homer wrote:
>
> 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
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
James McGill





PostPosted: 2006-4-18 2:52:00 Top

java-programmer >> How to get you Extenal/Real IP (Router) On Mon, 2006-04-17 at 11:36 -0700, Homer wrote:
>
> - 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





PostPosted: 2006-4-18 3:36:00 Top

java-programmer >> How to get you Extenal/Real IP (Router)
> - 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
 
 
Martin Gregorie





PostPosted: 2006-4-18 3:45:00 Top

java-programmer >> How to get you Extenal/Real IP (Router) Homer wrote:
> 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.


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





PostPosted: 2006-4-18 3:57:00 Top

java-programmer >> How to get you Extenal/Real IP (Router) 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





PostPosted: 2006-4-18 4:00:00 Top

java-programmer >> How to get you Extenal/Real IP (Router)
"Homer" <email***@***.com> wrote in message
news:email***@***.com...
> 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).
>

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

- Oliver

 
 
Homer





PostPosted: 2006-4-18 4:27:00 Top

java-programmer >> How to get you Extenal/Real IP (Router) 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





PostPosted: 2006-4-18 5:14:00 Top

java-programmer >> How to get you Extenal/Real IP (Router)
"Homer" <email***@***.com> wrote in message
news:email***@***.com...
> 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

 
 
Alex Hunsley





PostPosted: 2006-4-18 6:55:00 Top

java-programmer >> How to get you Extenal/Real IP (Router) Homer wrote:
> 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





PostPosted: 2006-4-18 7:17:00 Top

java-programmer >> How to get you Extenal/Real IP (Router)
"Homer" <email***@***.com> wrote in message
news:email***@***.com...
> 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.



 
 
Roedy Green





PostPosted: 2006-4-18 7:24:00 Top

java-programmer >> How to get you Extenal/Real IP (Router) On Mon, 17 Apr 2006 18:59:22 +0100, Thomas Hawtin
<email***@***.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

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





PostPosted: 2006-4-18 7:24:00 Top

java-programmer >> How to get you Extenal/Real IP (Router) On Mon, 17 Apr 2006 21:13:38 GMT, "Oliver Wong" <email***@***.com>
wrote, quoted or indirectly quoted someone who said :

> 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
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
 
David Segall





PostPosted: 2006-4-18 14:33:00 Top

java-programmer >> How to get you Extenal/Real IP (Router) "Homer" <email***@***.com> wrote:

>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.
 
 
Homer





PostPosted: 2006-4-18 20:42:00 Top

java-programmer >> How to get you Extenal/Real IP (Router) 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





PostPosted: 2006-4-18 20:55:00 Top

java-programmer >> How to get you Extenal/Real IP (Router) 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";

 
 
Homer





PostPosted: 2006-4-18 22:03:00 Top

java-programmer >> How to get you Extenal/Real IP (Router) 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.

 
 
Amfur Kilnem





PostPosted: 2006-4-18 22:06:00 Top

java-programmer >> How to get you Extenal/Real IP (Router)
"Homer" <email***@***.com> wrote in message
news:email***@***.com...
> 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.