How can I find the public facing IP for my net work in Python?
netaddr is a Python library for representing and manipulating network addresses. IPAddress('input ip'). is_private() will return true if the input ip address private, else it will return false.
Type "ipconfig" in the command prompt window and take note of the IP address displayed. If you have multiple network ports in use, like an Ethernet port and a Wi-Fi adaptor, you may see more than one. On a macOS or Linux system, you can use the similarly named "ifconfig" command line tool for the same purpose.
This will fetch your remote IP address
import urllib ip = urllib.urlopen('http://automation.whatismyip.com/n09230945.asp').read()
If you don't want to rely on someone else, then just upload something like this PHP script:
<?php echo $_SERVER['REMOTE_ADDR']; ?>
and change the URL in the Python or if you prefer ASP:
<% Dim UserIPAddress UserIPAddress = Request.ServerVariables("REMOTE_ADDR") %>
Note: I don't know ASP, but I figured it might be useful to have here so I googled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With