detecting enabled network interfaces in win32

Michael Loritsch loritsch at gmail.com
Sun Oct 17 15:19:34 EDT 2004


matt.torment at gmail.com (Matthew K Jensen) wrote in message news:<a8dfce8c.0410162113.545a74bb at posting.google.com>...
> In one of my "because I can" projects, I want to be able to see the
> enabled network interfaces on a machine. I have no clue as to how to
> do this. Any suggestions?

Use the WSAIoctl function of Winsock2 with the command (2nd parameter)
dwIoControlCode = SIO_GET_INTERFACE_LIST.

The other key important tidbit of information would be that you will
need to pass the address of an array of INTERFACE_INFO structures to
the output buffer (5th parameter - lpvOutBuffer) to obtain structures
containing the information you desire.

Below are links to the MSDN documentation of both the WSAIoctl
function and the INTERFACE_INFO structure.

Documentation for WSAIoctl:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsaioctl_2.asp
Documentation for INTERFACE_INFO:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/interface_info_2.asp

I don't that this function is exposed through any of the win32 python
extensions, although I have not had time to research this in order to
be sure.

For that reason, you would likely have to access this method using
ctypes.

Enjoy, and please let me know when you've written such a script
because I'd love to use it. =)

Michael Loritsch



More information about the Python-list mailing list