简体   繁体   中英

PHP - find server's public IP address

Is there an option in PHP to find the public IP address of the server, without using 3rd party services ?

Sounds impossible but may be...

It is impossible. The web server just receives requests. How these requests are routed to it and what IPs are used in the process it cannot know. It cannot inspect how the outside world looks at it. There's a whole world of routers and NATs and networks around it that it cannot know about.

Even with a third party service it's not guaranteed that it'll get the same IP that other clients will contact it on. Outgoing requests may use a different interface and routing than incoming requests.

The best you can do is to resolve a domain name to an IP address using a DNS query, and guess that this is the same thing that anyone else is doing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM