Getting my ip address
Asked Answered
N

12

8

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.

Nourishment answered 27/5, 2009 at 18:36 Comment(7)
Scraping some external service like you've already done is probably good enough. It might even be the only way. Your router and/or modem to the internet will know your real ip. I don't know how you will programmatically interface with that.Esqueda
whatismyip.org provides a simpler page for scraping.Esqueda
What do you need your IP for? If you want a static address, use DynDNS or similar. After that, you can install servers for your needs (remote control, HTTP/FTP/SSH...)Evaluate
Thanks Albert, didn't know about that site. Much easier than ip-address.comNourishment
Your real IP is 192.168.2.100. Your question should be "What is my Internet IP Address?".Taal
Related: #66863 #1162498Tyrant
"I am trying to get my real ip." The IP address you give, 192.168.2.100, is a real IP address. It is a private IP address, as defined by RFC 1918, but it is a real IP address. The only difference between it an a public address is that ISPs block RFC 1918 addresses from traversing the public Internet. Your private address can do anything a public address can do, just not on the public Internet.Cracknel
N
12

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.

Nyhagen answered 27/5, 2009 at 18:42 Comment(0)
D
6

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

Direct answered 28/5, 2009 at 14:56 Comment(0)
O
3

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.

Ohara answered 27/5, 2009 at 18:43 Comment(1)
Nice idea :) Simple and easy.Nourishment
A
2

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.

Artifice answered 27/5, 2009 at 18:41 Comment(0)
D
2

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

Downdraft answered 27/5, 2009 at 18:50 Comment(0)
S
2

You can also access this page to get your IP

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

Seismology answered 25/11, 2009 at 4:14 Comment(0)
P
1

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.

Papillary answered 27/5, 2009 at 18:43 Comment(0)
S
1

When I need to check my public ip address, I like this website:

http://www.whatismyip.global/

The website keeps a history of your IPs. For me is very usefull!

Sallyanne answered 28/3, 2016 at 19:30 Comment(0)
C
0

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.

Cowbind answered 27/5, 2009 at 18:42 Comment(0)
B
0

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.

Bridgettebridgewater answered 27/5, 2009 at 18:44 Comment(0)
G
0

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
Greiner answered 27/5, 2009 at 18:45 Comment(0)
E
0

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.
Extrauterine answered 27/5, 2009 at 19:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.