[Tutor] Monitoring an Internet connection in Python

Lloyd Hugh Allen chandrakirti at gmail.com
Wed Oct 13 23:44:27 CEST 2004


I did this for a linksys befw11sf4 802.11b router. In particular, I
wanted it to email me when my IP address changed. It works pretty well
for a week or two, and then the computer pretty much grinds to a halt.
I didn't know whether the fault was with my script, with Python, or
with Windows 98 (under which my desktop computer runs).

I had used urllib2 to load the "Status" page from the router, and then
watched for changes to the IP address. A second problem was that it
would occasionally try to mail me when the address had changed to
0.0.0.0, which ran into problems...

I also had used smtplib to send the message to myself.

This kind of thing demonstrates the "batteries included"ness of
Python. I didn't really feel like writing a mail or telnet client, nor
web browser, and so was happy that all of these things were built in.


On Wed, 13 Oct 2004 17:17:29 -0400, Kent Johnson
<kent_johnson at skillsoft.com> wrote:
> I have a DSL router with a built-in web server. One of the web pages shows
> the connection status. It would be pretty simple to write a Python script
> to poll the router web page and extract the status.
> 
> Kent
> 
> 
> 
> At 12:50 PM 10/13/2004 -0700, Terry Carroll wrote:
> >My DSL connection is pretty fragile, and tends to drop a lot, and for
> >extended periods.  I'd like to write a Python program to periodicaly (say,
> >every 5 minutes or so) check the status of the Internet connection, and
> >log any change in status (detecting when it becomes unavailable and when
> >it becomes available again), so I can document the failures to SBC.
> >
> >What's the best way to check whether my system has a working Internet
> >connection using Python?  My thinking is to select a few IP addresses
> >known to be reliable, and to define "connection available" as being when
> >at least one of those sites responds to a ping.  Is there a better way?
> >
> >
> >
> >_______________________________________________
> >Tutor maillist  -  Tutor at python.org
> >http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list