Thanks for the tip, it is really helpful!<div>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:</div>
<div><br></div><div><div>import wmi</div><div><br></div><div>wlan_int_id=None</div><div>for nic in wmi.WMI().Win32_NetworkAdapter():</div><div> if nic.NetConnectionID == "Wireless Network Connection":</div><div>
wlan_int_id=nic.Index</div><div> break</div><div><br></div><div>if wlan_int_id<>None:</div><div> for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1):</div><div> if nic.Index==wlan_int_id:</div>
<div> print nic.IPAddress[0]</div><div>else:</div><div> print "WLAN interface NOT Found"</div><div><br></div><div><br><br><div class="gmail_quote">On Sun, May 15, 2011 at 4:12 AM, Tim Golden <span dir="ltr"><<a href="mailto:mail@timgolden.me.uk">mail@timgolden.me.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On 15/05/2011 12:04 PM, Neal Becker wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Far.Runner wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi python experts:<br>
There are two network interfaces on my laptop: one is 100M Ethernet<br>
interface, the other is wifi interface, both are connected and has an ip<br>
address.<br>
The question is: How to get the ip address of the wifi interface in a python<br>
script without parsing the output of a shell command like "ipconfig" or<br>
"ifconfig"?<br>
<br>
OS: Windows or Linux<br>
<br>
F.R<br>
</blockquote>
<br>
Here's some useful snippits for linux:<br>
</blockquote>
<br></div>
... and for Windows:<br>
<br>
<code><br>
import wmi<br>
<br>
for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1):<br>
print nic.Caption, nic.IPAddress<br>
<br>
</code><br>
<br>
TJG<div><div></div><div class="h5"><br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br></div></div>