Thanks for the tip, it is really helpful! however the class of Win32_NetworkAdapterConfiguration doesn't include the interface type (you can NOT tell if it is a wifi interface), so I change the code a bit like following:
import wmi wlan_int_id=None for nic in wmi.WMI().Win32_NetworkAdapter(): if nic.NetConnectionID == "Wireless Network Connection": wlan_int_id=nic.Index break if wlan_int_id<>None: for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): if nic.Index==wlan_int_id: print nic.IPAddress[0] else: print "WLAN interface NOT Found" On Sun, May 15, 2011 at 4:12 AM, Tim Golden <m...@timgolden.me.uk> wrote: > On 15/05/2011 12:04 PM, Neal Becker wrote: > >> Far.Runner wrote: >> >> Hi python experts: >>> There are two network interfaces on my laptop: one is 100M Ethernet >>> interface, the other is wifi interface, both are connected and has an ip >>> address. >>> The question is: How to get the ip address of the wifi interface in a >>> python >>> script without parsing the output of a shell command like "ipconfig" or >>> "ifconfig"? >>> >>> OS: Windows or Linux >>> >>> F.R >>> >> >> Here's some useful snippits for linux: >> > > ... and for Windows: > > <code> > import wmi > > for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1): > print nic.Caption, nic.IPAddress > > </code> > > TJG > > -- > http://mail.python.org/mailman/listinfo/python-list >
-- http://mail.python.org/mailman/listinfo/python-list