views:

1231

answers:

3

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

+5  A: 

This will fetch your remote IP address

import urllib
ip = urllib.urlopen('http://www.whatismyip.com/automation/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.

Unkwntech
+3  A: 

whatismyip.org is better... it just tosses back the ip as plaintext with no extraneous crap.

import urllib
ip = urllib.urlopen('http://whatismyip.org').read()

But yeah, it's impossible to do it easily without relying on something outside the network itself.

Steve Losh
Neither does the link I reference, it also just returns the raw IP address.
Unkwntech
A: 

One way is , you can make a request to the page at

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

it returns the IP address of your system

Biranchi