Getting my ip address

2019-01-24 09:29发布

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.

12条回答
倾城 Initia
2楼-- · 2019-01-24 09:29

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

查看更多
何必那么认真
3楼-- · 2019-01-24 09:32

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.

查看更多
等我变得足够好
4楼-- · 2019-01-24 09:32

You can also access this page to get your IP

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

查看更多
Root(大扎)
5楼-- · 2019-01-24 09:32

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.

查看更多
男人必须洒脱
6楼-- · 2019-01-24 09:33

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.

查看更多
对你真心纯属浪费
7楼-- · 2019-01-24 09:34

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.

查看更多
登录 后发表回答