myip.org - dns client

Skip Montanaro skip at mojam.com
Thu Nov 9 08:08:31 EST 2000


    Anders> There are some clients at the myip.org site, but they are
    Anders> written in perl and my computer is a perl free zone!

I'll probably make a mistake transcribing the perl code (and since I don't
use myip.org I can't really test it anyway), but here's a first cut that
should get you close.

    import urllib, os, re

    # modify to suit your environment and myIP account info
    interface = "ppp0"
    userid = "myiploginname"
    pwd = "myippassword"
    hostname = "spamneggs.myip.org"
    recordtype = "A"
    # end of modification section

    ipdata = os.popen("ifconfig " + interface)
    ipaddress = None
    for line in ipdata.readlines():
	mat = re.search(r"addr:(\d+\.\d+\.\d+\.\d+)")
	if mat is not None:
	    ipaddress = mat.group(1)
	    break
    ipdata.close()

    if ipaddress is None:
       raise ValueError, "couldn't read my IP address!"

    f = urllib.urlopen("http://www.myip.org/cgi-bin/Update.py?"
		       "id=%(userid)s&pwd=%(pwd)s&hostname=%(hostname)s&"
		       "ip=%(ipaddress)s&recordtype=%(recordtype)s")

    print f.read()

-- 
Skip Montanaro (skip at mojam.com)
Support the Mojam.com Affiliates Program: http://www.mojam.com/affl/
(847)971-7098




More information about the Python-list mailing list