Lan Barnes wrote: > Cox (rhymes with "Cox") has been spontaneously switching my home IP > address recently. It locks me out to ssh. > > I want to use expect and lynx to write a script that logs into the > D-Link router as a browser does, navigates to the place where the WAN IP > address is shown, reads it, and sends me an email at work if it's > changed. > > However, experiments with lynx accessing the router result in no joy. > > Looking up 192.168.xxx.1 first > Looking up 192.168.xxx.1 > Making HTTP connection to 192.168.xxx.1 > Sending HTTP request. > HTTP request sent; waiting for response. > Alert!: Access without authorization denied -- retrying > Retrying with access authorization information. > Looking up 192.168.xxx.1 > Making HTTP connection to 192.168.xxx.1 > Sending HTTP request. > HTTP request sent; waiting for response. > Alert!: Unexpected network read error; connection aborted. > Can't Access `http://192.168.xxx.1/' > Alert!: Unable to access document. > > lynx: Can't access startfile > > I suspect the " Access without authorization denied" step means that the > router embedded program's asking for admin/passwd (and I do get asked > for this within lynx) is not somehow getting properly authenticated to > the router. Some java thing? > > Q1: Is there some setting for lynx that will make this bad thing not > happen? > > Q2: Is there an alternative way of "pinging" the router to get the WAN > address, preferably with a CLI program? >
Here's a python-solution (lifted from Rene Olsthoorn, 2004/06/18 discussion at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/267197) <pre> import urllib2, base64 request = urllib2.Request('http://192.168.1.1/Status.htm') base64string = base64.encodestring('%s:%s' % ('user', 'password'))[:-1] request.add_header("Authorization", "Basic %s" % base64string) htmlFile = urllib2.urlopen(request) htmlData = htmlFile.read() print htmlData htmlFile.close() </pre It works on my D-Link DI-604 if I use the appropriate page address there http://192.168.1.1/st_devic.html And of course, my auth info is much more sophisticated ('admin', 'admin') If there is no addressable page (ie, there's some javascript or frame messiness, then I suppose you might have to go with something like expect. In any case, the auth magic, pretty simply adds a header item to the request, which looks like Authorization: Basic QWRtaW46Zm9vYmFy ..jim -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list
