views:

364

answers:

2

I'm working on a project that requires that I can reliably detect the presence of a wireless capability on both a PC and a Mac.

Ideally I would want to achieve this through an existing command line tool I could package with my application or that perhaps already exists on the OS.

By wireless capability I mean the presence of a wireless network adapter on a Desktop PC, or built in wireless on a laptop or even a Wireless Dongle/USB Key - basically the presence of any device or component that will allow a connection to a wireless router.

I've been looking into simply capturing output from "ipconfig /all" or "systeminfo" on the PC and "system_profiler" on the Mac... then parsing for known wireless adapters and keywords but this doesn't seem like an ideal solution.

Are there any APIs I can use to achieve this on either platform?

EDIT: Ideally the platforms I would like to support are:

Windows: 2000/XP/Vista/7 Mac: 10.4/.5/.6

+1  A: 

You will find Managed Wifi API to be useful

waqasahmed
+1  A: 

Instead of ipconfig why don't you simply query the all-in-one tool for network configuration, netsh?

When a WiFi device is present:

> netsh wlan show drivers

Interface name: Wireless Network Connection

    Driver                    : Intel(R) PRO/Wireless 3945ABG Network Connection
    Vendor                    : Intel Corporation
    Provider                  : Microsoft
    Date                      : 2009-03-26
    Version                   : 12.4.1.4
    INF file                  : C:\Windows\INF\netw5v64.inf
    Files                     : 1 total
                                C:\Windows\system32\DRIVERS\netw5v64.sys
    Type                      : Native Wi-Fi Driver
    Radio types supported     : 802.11a 802.11b 802.11g
    FIPS 140-2 mode supported : Yes
    Hosted network supported  : No
    Authentication and cipher supported in infrastructure mode:
                                Open            None
                                Open            WEP-40bit
                                Open            WEP-104bit
                                Open            WEP
                                Shared          WEP-40bit
                                Shared          WEP-104bit
                                Shared          WEP
                                WPA-Enterprise  TKIP
                                WPA-Enterprise  CCMP
                                WPA-Personal    TKIP
                                WPA-Personal    CCMP
                                WPA2-Enterprise TKIP
                                WPA2-Enterprise CCMP
                                WPA2-Personal   TKIP
                                WPA2-Personal   CCMP
                                Open            Vendor defined
    Authentication and cipher supported in ad-hoc mode:
                                Open            None
                                Open            WEP-40bit
                                Open            WEP-104bit
                                Open            WEP
                                Shared          WEP-40bit
                                Shared          WEP-104bit
                                Shared          WEP
                                WPA2-Personal   CCMP

When there is no WiFi NIC in the computer, the Wireless AutoConfig service is likely not running (because it isn't needed):

> netsh wlan show drivers
The Wireless AutoConfig Service (wlansvc) is not running.

but even when it's started manually:

> netsh wlan show drivers
There is no wireless interface on the system.
Joey
Thanks - this sounds like a good solution for the Windows platform. I do need to support Windows 2000/XP/Vista/7 though... would this work on all those OSs?
Shrill
netsh certainly exists on Windows 2000 onwards, but real OS-level WiFi capability didn't exist until Windows Vista. In XP it was more of a hack than any real support, although you might get lucky there. On Windows 2000 WiFi was managed solely by the NIC's driver software so you can't reliably detect it there.
Joey
Ahh I see. Would it be possible to use netsh wlan under XP? Do you need to install a hotfix for this option to appear? otherwise could I get similar functionality through the Wireless Zero Configuration service somehow?
Shrill
I doubt you'll get this in XP at all. As mentioned, XP has very limited WiFi capability. You may be better off there with the native WiFi APIs (which the Managed WiFi API mentioned by waqasahmed also use)
Joey