Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5443 > unrolled thread

Re: Get the IP address of WIFI interface

Started byTim Golden <mail@timgolden.me.uk>
First post2011-05-15 20:38 +0100
Last post2011-05-15 20:38 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Get the IP address of WIFI interface Tim Golden <mail@timgolden.me.uk> - 2011-05-15 20:38 +0100

#5443 — Re: Get the IP address of WIFI interface

FromTim Golden <mail@timgolden.me.uk>
Date2011-05-15 20:38 +0100
SubjectRe: Get the IP address of WIFI interface
Message-ID<mailman.1598.1305488324.9059.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web