views:

270

answers:

4

Looking for a better way to get a machines current external IP #...Below works, but would rather not rely on an outside site to gather the information ... I am restricted to using standard Python 2.5.1 libraries bundled with Mac OS X 10.5.x

import os
import urllib2

def check_in():

    fqn = os.uname()[1]
    ext_ip = urllib2.urlopen('http://whatismyip.org').read()
    print ("Asset: %s " % fqn, "Checking in from IP#: %s " % ext_ip) 
+2  A: 

If the machine is being a firewall then your solution is a very sensible one: the alternative being able to query the firewall which ends-up being very dependent on the type of firewall (if at all possible).

jldupont
+4  A: 

If you are behind a router which obtains the external IP, I'm afraid you have no other option but to use external service like you do. If the router itself has some query interface, you can use it, but the solution it will be very environment specific and unreliable.

Sunny
A: 

Just as an alternative. Here's a script you can try out.

ghostdog74
A: 

Some ip sites have created specific services for scripts like yours, in order to reduce the hit on their sites.

    www.whatismyip.com/automation/n09230945.asp
Thomas Ahle