Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5443
| Date | 2011-05-15 20:38 +0100 |
|---|---|
| From | Tim Golden <mail@timgolden.me.uk> |
| Subject | Re: Get the IP address of WIFI interface |
| References | <BANLkTi=YN7CW_y3w5EK-36uPwPcxXgPm8A@mail.gmail.com> <iqobvs$3jn$1@dough.gmane.org> <4DCFB507.2040007@timgolden.me.uk> <BANLkTinm0QLnF4QTK6tAPe8-+xzS3--8OQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1598.1305488324.9059.python-list@python.org> (permalink) |
On 15/05/2011 20:23, Jun Hu wrote:
> 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"
Glad it was useful; you can get a little bit prettier:
<code>
import wmi
c = wmi.WMI ()
for nic in c.Win32_NetworkAdapter (
NetConnectionID="Wireless Network Connection"
):
for config in nic.associators (
wmi_result_class="Win32_NetworkAdapterConfiguration"
):
print config.Caption, "=>", " / ".join (config.IPAddress)
break
else:
print "No Wireless NIC found"
</code>
TJG
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Get the IP address of WIFI interface Tim Golden <mail@timgolden.me.uk> - 2011-05-15 20:38 +0100
csiph-web