[python-win32] Re: Connection State on windows

Thomas Heller theller at python.net
Tue Sep 16 02:59:44 EDT 2003


"luther" <luther at terra.com.br> writes:

> Hello all,
> 
> I'm trying to write a program that needs to be aware of the internet
> connection state, if the computer is online or not. Well I have
> searched the Universe for this, and I know that I have to make a call
> to a function called InternetGetConnectedState wich is in the
> wininet.dll, windows stuff. The problem is I can't find a way to do
> this. I found a module named win32inet, but it is for python 2.0 and
> I'm running 2.2
> I'm getting crazy about this, can someone help me?
> 
You need ctypes http://starship.python.net/crew/theller/ctypes/

    from ctypes import *
    from ctypes.wintypes import DWORD

    wininet = windll.wininet
    flags = DWORD()
    connected = wininet.InternetGetConnectedState(byref(flags), None)
    print connected, hex(flags.value)

This prints "1 0x12L" for me.

Thomas




More information about the Python-win32 mailing list