Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding a public facing IP address in Python?

Tags:

How can I find the public facing IP for my net work in Python?

like image 824
UnkwnTech Avatar asked Oct 03 '08 12:10

UnkwnTech


People also ask

How do you check a IP is public or private 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.

How do I find my external facing IP address?

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.


1 Answers

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.

like image 57
UnkwnTech Avatar answered Oct 17 '22 04:10

UnkwnTech