Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old September 23rd, 2003, 08:33 PM
coscarart coscarart is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 4 coscarart User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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('<.*?>|&nbsp','',status) #parse out html tags and &nbsp
	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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Python and Regular expressions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT