import urllib, time, re, os, smtplib, string dataFile = "/tempip.html" configFile = "/configip.dat" ipAddress = "" i = "1" def loadConfig(): if os.path.exists(configFile): cfgSize = os.stat(configFile).st_size cfgFile = file(configFile,"r") cfgBuffer = cfgFile.read(cfgSize) cfgFile.close() print "Configuration file present." print "Configuration file size is: ", cfgSize query = re.compile('[0-9]{2}\.[0-9]{2}\.[0-9]{2,3}\.[0-9]{2,3}') match = query.search(cfgBuffer) if match: print "Configuration file IP address is: ", match.group(), "\n\n" global ipAddress ipAddress = match.group() else: print "No IP address found in configuration file...\n\n" else: print "No configuration file present. Loading without...\n\n" def getData(): urllib.urlretrieve("http://gateway.2wire.net/broadband/index.html",dataFile) urllib.urlcleanup() def parseData(): if os.path.exists(dataFile): ipSize = os.stat(dataFile).st_size ipFile = file(dataFile,"r") ipBuffer = ipFile.read(ipSize) ipFile.close() query = re.compile('[0-9]{2}\.[0-9]{2}\.[0-9]{2,3}\.[0-9]{2,3}') match = query.search(ipBuffer) if match: currentIP = match.group() if currentIP != ipAddress: newIP(currentIP) os.remove(dataFile) def newIP(address): print time.ctime(),"| IP Address changed to: ", address global ipAddress ipAddress = address writeConfig(address) notify(address) def notify(address): fromAddress = "IPFinder " toAddress = ["someone@somewhere.com", "someoneElse@somewhereElse.com"] subject = "IPFinder Address Reporting" info = time.ctime() + " | IP Address changed to: " + address myMessage = "Date: " + time.ctime() + "\r\nFrom: " + fromAddress + "\r\nSubject: " + subject + "\r\nTo: " + string.join(toAddress, ", ") + "\r\n\r\n" + str(info) server = smtplib.SMTP("smtp.server") server.login("username","password") server.sendmail(fromAddress,toAddress,myMessage) def writeConfig(address): writeString = str(address) cfgFile = file(configFile,"w") cfgFile.truncate(0) cfgFile.write(writeString) cfgFile.close() print "System Initializing..." loadConfig() while i == "1": getData() parseData() time.sleep(600)