Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Windows: hook on network up/down?

46 views
Skip to first unread message

David N. Welton

unread,
Dec 1, 2005, 6:05:48 PM12/1/05
to
Hi - this isn't a particularly Tcl related question, but if I find an
answer, most likely I will write a bit of code to make it accessible to
Tcl...

Does anyone know if it's possible to hook into Windows' detection of the
network being connected or not, via some sort of C API?

--
David N. Welton
- http://www.dedasys.com/davidw/

Linux, Open Source Consulting
- http://www.dedasys.com/

Robert Hicks

unread,
Dec 1, 2005, 6:19:15 PM12/1/05
to
So I don't misunderstand what you mean...what do you mean by "network
being connected or not"?

TWAPI has various Network related things in it but I am not sure if
they are what you are after.

Robert

Robert Hicks

unread,
Dec 1, 2005, 6:26:59 PM12/1/05
to
I found this on the wiki:

# twapi requires full path for program files
set nsfile [file join $::env(windir) system32 netstat.exe]
set opts [list -cmdline "-a -o 5"]
set e [catch {eval twapi::create_process $nsfile $opts} result]

This will capture network status every 5 seconds... : )

David N. Welton

unread,
Dec 2, 2005, 3:54:42 AM12/2/05
to Robert Hicks

Cool, that's close - thanks! The ideal thing would be to hook into
whatever API is related to that little message that pops up when you
unplug the ethernet cable, so that I don't have to poll...

David Gravereaux

unread,
Dec 2, 2005, 11:54:39 AM12/2/05
to
David N. Welton wrote:
> Robert Hicks wrote:
>
>>I found this on the wiki:
>>
>> # twapi requires full path for program files
>> set nsfile [file join $::env(windir) system32 netstat.exe]
>> set opts [list -cmdline "-a -o 5"]
>> set e [catch {eval twapi::create_process $nsfile $opts} result]
>>
>>This will capture network status every 5 seconds... : )
>
>
> Cool, that's close - thanks! The ideal thing would be to hook into
> whatever API is related to that little message that pops up when you
> unplug the ethernet cable, so that I don't have to poll...
>


There's an WSAIoctl call for detecting route changes that isn't polling,
but you need a thread for it and there's possibly some stuff in the IP
helper api, too.

WSAIoctl called for SIO_ROUTING_INTERFACE_CHANGE or
SIO_ADDRESS_LIST_CHANGE might work.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsaioctl_2.asp?frame=true

There's a more "packaged" version of the same in the IP helper API with
a quick sample.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/notifyaddrchange.asp?frame=true
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/notifyroutechange.asp?frame=true

There's a "network location awareness" API, too, but I don't think it
works in XP yet.

0 new messages