Get my WAN IP

How can I programmatically obtain the IP address of my network, as seen from the Internet? Obviously, this is a property that my router has access to when it connects to your ISP. Is there a way to get this information from the router using a standard protocol. My only other option is to either find a WS that returns my IP address (which is surprisingly hard to do), or just go to something like whatismyip.com and cross out all the HTML (very dirty and susceptible to change). Is there any other way ???

+3
source share
4 answers

Do not clean whatismyip.com, see here for what you can call their API, which simply returns your address.

If you are not using this, you should write something like this yourself, that is, a node outside of your router that can communicate your visible address.

Please note that the web server may not see your real WAN IP address because:

  • Your Internet service provider may be transparently proxying HTTP traffic, and the server will see the IP address of the proxy. In this case, you usually need to search and analyze X-Forwarded-For .

  • , , NAT- , , WAN . , , whatismyip.com, - IP- NAT.

+8

, , :

  • - - -. , , ,
  • -, (HTTP-Header X-Forwarded-For), , -
  • ( - -) .

, .

+2

, , python: IP- Python?
, , http://www.whatismyip.com/automation/n09230945.asp, IP-. script, PHP:

<?php
echo $_SERVER['REMOTE_ADDR'];
?>
+1

Source: https://habr.com/ru/post/1697966/


All Articles