Possible to save router logs?

Mikke M. plopp at dummyaddress.doh
Sun Mar 31 14:44:35 EST 2002


"Paul" <Luap777 at hotmail.com> wrote in message
news:bbde2416.0203310724.4150665d at posting.google.com...
> I have a D-Link 704 cable/DSL router. Unfortunately, it has very
> limited logging capabilities(in that it doesn't save logs, it just
> rights over them when the space fills.) What I would like to do is
> right a program to save the logs to my hard drive every 12 hours or
> so. I normally have to access the web page with the url being the
> local IP of the router, then type in a password to get access to the
> logs. Has anyone attempted something like this? I know this is kinda
> general, but any feedback would be appreciated. It might give me an
> idea of where to begin. Thank you.

Sure.. First of all you have to log on to the router.  My DL-704 shows this
html code:


---(SNIP!)---
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=iso-8859-1"><SCRIPT LANGUAGE=JavaScript><!--
function GURL(x){var t=new Date(); location=x+'&ZT='+t.getTime();}
function makesure(p,l){if (confirm(p)) GURL(l);}
//--></SCRIPT></HEAD><BODY TEXT=#000000 BGCOLOR=#FFFFFF LINK=#006693
VLINK=#006693 ALINK=#006693>
<!--H3 ALIGN=CENTER>User's Main Menu</H3-->
<CENTER>
<FORM ACTION=/cgi-bin/logi METHOD=POST NAME=LOGIN>
<INPUT TYPE=HIDDEN VALUE="@D" NAME=RC>
<INPUT TYPE=HIDDEN VALUE="root" NAME=ACCT>
<INPUT TYPE=HIDDEN VALUE="458:06:54 (S=00:00:00,P=0)" NAME=PSWD>
<font size="+2">System Password</font> 
<INPUT TYPE=PASSWORD NAME=URL SIZE=9 MAXLENGTH=9><INPUT TYPE=HIDDEN
VALUE="3A2D.36D6.3A43/3100+ADB0 at Winnie 193s" NAME=KEY><INPUT TYPE=HIDDEN
VALUE="2.56 build 20" NAME=htm>
<INPUT TYPE=SUBMIT VALUE="Log in"></FORM>
<SCRIPT LANGUAGE=JavaScript><!--
var t=new Date();
function reload() { GURL("/menu.htm?RC=") }
function refresh() { GURL("/menu.htm?RC=@") }
document.LOGIN.URL.focus();
parent.main.location="/begin.htm?RC=@&ZT="+t.getTime();
//--></SCRIPT>
</CENTER>
</BODY></HTML>
---(SNIP!)---

The tricky part for me was getting the encoded password to submit to the
router, so I rewrote the FORM ACTION command to read:
<FORM ACTION=http://my.router.ip/cgi-bin/logi METHOD=GET NAME=LOGIN>

Then I saved the html to a file and opened it, and logged on to the router
using that file and copied the entire address line from internet explorer
and pasted it into my python script:

---(snip!)---
import urllib2
MR=urllib2.Request("http://my.router.ip/cgi-bin/logi?RC=@D&ACCT=root&PSWD=TH
E ENCODED PASSWORD GOES
HERE..&URL=admin&KEY=3A2D.36D6.3A43%2F3100%2BADB0 at Winnie+193s&htm=2.56+build
+20")

URL=urllib2.urlopen(MR)
---(snip!)---

Now you are logged on to your router and it will gladly show any of its
internal webpages you request from it witin a couple of minutes..

Then go on to get the system log page:
---(snip!)---
MR=urllib2.Request("http://my.router.ip/syslog.htm")
URL=urllib2.urlopen(MR)
LOGPAGE= URL.read()
---(snip!)---

Now you should have the entire system log webpage in LOGPAGE, the rest of
the work is up to you. :-)

/Mikke










More information about the Python-list mailing list