Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'from:addr:timgolden.me.uk': 0.09; 'from:name:tim golden': 0.09; 'message-id:@timgolden.me.uk': 0.09; 'wifi': 0.09; 'wrote:': 0.14; 'found"': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject:interface': 0.16; 'wmi': 0.16; 'subject:address': 0.16; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'interface': 0.20; 'code': 0.22; 'header:In- Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'skip:( 30': 0.24; "doesn't": 0.28; 'thanks': 0.29; '(you': 0.29; 'class': 0.29; 'cc:addr:python.org': 0.31; 'tjg': 0.31; 'import': 0.32; 'bit': 0.33; 'break': 0.33; 'wireless': 0.33; 'received:192.168.1': 0.34; 'received:192': 0.34; 'change': 0.34; 'print': 0.35; 'header:User- Agent:1': 0.35; 'received:192.168': 0.37; 'however': 0.37; 'include': 0.40; 'from:addr:mail': 0.60; 'glad': 0.64; 'subject:Get': 0.74; 'skip:w 50': 0.77; 'to:none': 0.92 Date: Sun, 15 May 2011 20:38:40 +0100 From: Tim Golden User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 CC: python-list@python.org Subject: Re: Get the IP address of WIFI interface References: <4DCFB507.2040007@timgolden.me.uk> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305488324 news.xs4all.nl 81484 [::ffff:82.94.164.166]:35922 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5443 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: 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" TJG