
September 23rd, 2003, 08:33 PM
|
|
Junior Member
|
|
Join Date: Sep 2003
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
I didn't look at urllib2, but it seems to require knowledge of classes (which I am skechy on) to create a database of the password (with the HTTPPasswordMgr objects) and then open the http connection. If you would like to help it would be great though!
edit:
Well I figured it out...
Here is the program to get the external ip address of an linksys defsr41 v2 and then use ez-ipupdate to update the dynamic dns service
Code:
#!/usr/bin/python2.2
import os
import re
from urllib2 import urlopen, unquote, Request
import base64
#various things needed
linksysurl = "http://192.168.0.1/Status.htm"
linksysuserpass = "username:password"
updateusername = "username:password"
updatehost = "the name of the host you wish to update"
def ExternalIP():
status = getlinksys(linksysurl) #Get status page and parse out externalip address
ipline = re.sub('<.*?>| ','',status) #parse out html tags and  
ipline = re.sub(';','\n',ipline) #change semicolons to new lines in order re.findall to work
ip = re.findall ('IP Address:.*',ipline) #parses out ip[0] = internal IP and ip[1] = external IP
ipiwant = re.sub ('[^0-9\.]','',ip[1])
#Check if the oldip = newip and if so return "error code"
file = open("/tmp/oldip",'r')
oldip = (file.read())
if ipiwant == oldip:
return 1
#write newip to file for later checking
file = open("/tmp/oldip",'w')
file.write(ipiwant)
file.close
return ipiwant
def UpdateIPAddress():
externalip = ExternalIP()
if externalip == 1:
return 1
#Uses unix program ez-ipupdate to update ip
os.system ("ez-ipupdate --address " + externalip + " --user "+updateusername+
" --service-type dyndns --host " + updatehost)
def getlinksys(url):
#get the webpage and return it
req = Request(url)
# for some reason must base64 encode the username and password
userpass64=base64.encodestring(unquote(linksysuserpass)).strip()
req.add_header('Authorization', 'Basic ' + userpass64)
return urlopen(req).read()
UpdateIPAddress()
Thanks for the help!
coscarart
Last edited by coscarart : September 24th, 2003 at 04:09 PM.
|