detecting enabled network interfaces in win32

M

Matthew K Jensen

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?
 
J

Josiah Carlson

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?

Parse the output of 'ipconfig /all' on NT/2k/XP/2k3 machines.
I'm sure it is available in the registry, I've been there before, but I
can't remember the key name. Use regedit to find the key with your
network interface to determine where you should be polling in general.


- Josiah
 
M

Michael Loritsch

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/d...ry/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
 
R

Roger Upole

If you have pywin32 installed, you can get the info thru WMI:

import win32com.client
wmi=win32com.client.GetObject('winmgmts:')
adapters=wmi.InstancesOf('win32_networkadapter')
for adapter in adapters:
for p in adapter.Properties_:
print p.Name, p.Value

hth
Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top