How to get you Extenal/Real IP (Router)

T

Thomas Hawtin

Homer said:
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
 
H

Homer

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
 
J

James McGill

- 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?
 
M

Martin Gregorie

Homer said:
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.
 
H

Homer

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).
 
O

Oliver Wong

Homer said:
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
 
H

Homer

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

Oliver Wong

Homer said:
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
 
A

Alex Hunsley

Homer said:
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.
 
A

Amfur Kilnem

Homer said:
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.
 
R

Roedy Green

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
 
D

David Segall

Homer said:
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.
 
H

Homer

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

Homer

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";
 
H

Homer

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

Amfur Kilnem

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top