[python-win32] Waiting for Wireless
Roger Upole
rwupole at msn.com
Thu Oct 26 05:46:27 CEST 2006
Tim Roberts wrote:
> As a self-proclaimed studly Win32 programmer, I'm embarrassed at not
> being able to find a neat solution to this. I come to you humbly,
> seeking coolness.
>
> I have a script on my laptop that runs after login and launches the
> tools that I use all the time, including the putty password agent, the
> Agent newsreader, and Firefox. My wireless card takes about 15 seconds
> to sync up with my access point and get an IP address, by which time my
> script is done and the tools are running. That means that Firefox
> always comes up complaining that it couldn't reach my home page. So,
> I'd like to have my script wait for connectivity before launching the
> tools. The question is, how can that be done?
>
> I could use os.system to poll the "ipconfig" command, but that's icky
> and not at all studly. I could loop on gethostaddr for localhost until
> it gets an IP, but even that's not studly, because there's no way to
> know that it's really the wireless adapter's IP address.
>
> There must be a way for me to ask the musical question, "does the
> network adapter called 'Wireless Network Adapter' have an IP address?"
> Does anybody know that tune?
>
You can list network adapters and their IP addresses using WMI:
import win32com.client
wmi=win32com.client.GetObject('winmgmts:')
adapters=wmi.InstancesOf('Win32_NetworkAdapterConfiguration')
for adapter in adapters:
print adapter.Properties_['Caption'], adapter.Properties_['IpAddress']
Roger
More information about the Python-win32
mailing list