views:

1525

answers:

13

Hey!

I have a computer on a small network, so my ip is 192.168.2.100.

I am trying to get my real ip. I download the no-ip client but that just seems like a lot of trouble for such a simple thing.

I created this php script that got http://www.ip-adress.com/ page and retrieved the ip it gave me.

Is there a simpler way? Either using C, WSH or something. Or if there is an easier way in php please tell me.

When I get the ip I'll uploaded it to my ftp site so that I can see the ip from work.

+2  A: 

If you want to get the eventual IP that the remote site seems when processing your traffic then the only way is to actually access a remote site. In many situations your computer may not be aware that the IP is getting changed by a proxy or a NAT server.

shoosh
+9  A: 

No, there's not really an easier way. Your computer really doesn't know the public IP it's behind -- there could any number of layers of NAT between it and the public internet. All it knows is that it receives messages at 192.168.2.100, and sends outgoing messages through the gateway at 192.168.2.1. It has no idea what happens after the packet hits the gateway.

Frank Farmer
A: 

The way you're doing it is probably as good as any.

You say you have a public FTP site -- do you also have a web site there? Your other option is to have your local machine access a php page on that public facing site. That php page can verify it's you and then use the $_SERVER['REMOTE_ADDR'] to record your external IP.

Clyde
+3  A: 

Not quite what you asked for but still applies to what you want. I setup a GMail Notifier on my home computer and go to the account activity page to see which IP address is accessing my Google acount. Secure, simple and works.

Pierre-Luc Simard
Nice idea :) Simple and easy.
AntonioCS
A: 

Some routers can tell you their external IP address via UPnP, or more specifically, the IGD protocol. If you happen to own an UPnP enabled router, you can try this. IStaticPortMapping::get_ExternalIPAddress sounds promising.

SNMP enabled devices can tell you their IP addresses, too. The OID to ask for is IP-MIB::ipAdEntAddr.

Tomalak
A: 

Unfortunately, you're server will most likely be completely oblivious to what it's own External address appears to be (as it might be set further upstream via some router/gateway)

You could have a look at this link

http://ip-address.domaintools.com/myip.xml

It might be a little easier to parse than what you're currently doing.

Eoin Campbell
A: 

I can't think of how you would resolve your IP address from the perspective of another machine. Here's a couple thoughts:

  • Automate the loading of the ip-adress.com page and parse it
  • Look at DynDNS
Kieveli
+2  A: 

I always use curl http://whatismyip.org to get my public IP while behind NAT.

Alan Haggai Alavi
A: 

Your computer has no information on any NAT or routing that takes place between it and the internet except which hop is the next one (usually your router's internal ip). It simply doesn't know at which hop the internal address gets translated into which public address.

Therefore there is no simple function or method you can call, in any language.

The only two ways are to ask someone else. How?:

  • Ask your NAT router (because it itself does the translation to a public ip) by fetching and parsing the right page on your router's admin site. Arguably most reliable, and fair.
  • Ask an external host how it sees you, by fetching and parsing a public service such as http://dynamic.zoneedit.com/checkip.html. An example in VB script is here.
Martijn Heemels
+6  A: 

Do note reinvent the wheel, there is a standard protocol, STUN (with already existing implementations), just for that. See also Discovering public IP programatically.

bortzmeyer
+1  A: 

You can also access this page to get your IP

http://www.biranchi.com/ip.php

Biranchi
+1  A: 

Recently I have using the IP detection from IP2Location.com. You need to open the website and get your current location as well as the IP address detect on the Website. It's so simple. You also can trace out some domain's IP address after you have ping them.

JaceyKala
A: 

It is very easy to have a secured domain names and Ip-address details through,http://www.whoisxy.com/ which was well known for DNS query,Ip to domain , domain to Ip.

it helped me and it will help you too

prasath