How to test if connected to the Internet

Ron Johnson ron.l.johnson at home.com
Mon May 7 18:57:45 EDT 2001


Daniel wrote:

> 
> Hi,
> 
> A few days ago, I wrote some code (see post on NNTP) that allowed
> posting a message to a newsgroup.  All goes well if the connection
> with the Internet (to my ISP) is already established, but how can I
> check if there is already a valid connection? And if there isn't a
> connection to the ISP, how do I dial in using Python code?
> 
>  I have tried http://py-howto.sourceforge.net/sockets/node6.html but
> don't seem to get anywhere...
> 
> Is there some (easy) example code available which lets me check if a
> connection to the Internet is established or not?  If not, how can I
> dial-in to my ISP using Python?

If using Linux/Unix, you could always try 
  /sbin/ifconfig eth0 |grep eth0
and if you find eth0, then proceed with your Python script.

-- 
 Ron Johnson, Jr.        Home: ron.l.johnson at home.com
 Jefferson, LA  USA      http://ronandheather.dhs.org
 "Is Python better or worse than Perl?"
  "Perl is worse than Python because people wanted it 
   worse." -Larry Wall, 10/14/1998



More information about the Python-list mailing list