.Net WiFi Programming

free wifiSome time ago I was asked to write some code to

  1. detect if a user had saved a connection to an Open/Public Wifi point, and
  2. delete it if it exists.

The code had to work on Windows 7, so using the Wi-Fi Direct feature wasn’t available to me.

I could do this using the Native WiFi API, except that doing that from .Net isn’t easy.

So I used the managedwifi wrapper which Monfort Engineering developed and made open source.

Everything worked well except …

The code would occasionally fail.  Much reading of documentation, and lots of head scratching happened.  This was the answer:

“All wireless LAN functions require an interface GUID for the wireless interface when performing profile operations. When a wireless interface is removed, its state is cleared from Wireless LAN Service (WLANSVC) and no profile operations are possible.”
WlanSetProfile function

What that means in practice:

  1. if the Wireless LAN Service is not running, then there is no WiFi running
  2. if the user has disabled the WiFi Adapter, then there is no WiFi to query.

So if 1 or 2 occurred, the code I wrote would fail.

The code to fix that was as simple as this:

Private Sub DeleteOpenWifi()
…..
If wifi.Interfaces.Length = 0 Then
     Exit Sub
End If

References:
How to Avoid Public WiFi Security Risks
About the Native Wifi API
Managed WiFi API (Codeplex)
Is there anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc?

Saturday Link Roundup

Mirror_Dinghy_on_Combs_ReservoirGroup Policy Search – powered by Windows Azure.

How to bring harmony to your mixed wired and wireless networks
The article discusses several different ways to cause your WiFi enabled Windows PCs to switch to a wired connection when it is available.  The one which impresses me is the use of DHCP Default Router Metric Base property.

Sandy Mackinnon’s unlikely voyage through the canals of Europe
In a Mirror Dinghy no less.

How to recover a “WiFi” password from a Windows PC.

Or, “I’ve forgotten my Wireless password and don’t know how to retrieve it from my Windows 7 PC.”

I didn’t either, until today.

The background was that a customer was trying to add an iPad to their home network, and wasn’t able to, because they forgot their WiFi password.  So they called up.

There are three ways I found to recover a WiFI password.

1. WirelessKeyView by NirSoft.
This utility works, but some anti-virus products report it as malware.  That is a bit of a put off for (less experienced) end users.
wirelesskeyview

WirelessKeyiew has the advantage of working on Windows XP as well.

2. LastPass.
The LastPass password manager has a built-in WiFi password import tool.  It works very well, but the flaw with LastPass is that you need to convince your user to install it, which means getting the user to sign up for a free account.
Lastpass WiFi 

3. Use the built-in Windows “netsh” command.
From an administrator command line, type:
     netsh wlan export profile key=clear
and then press Enter.

Interface profile "GoldFish" is saved in file ".\Wireless Network Connection
-GoldFish.xml" successfully.

This will cause “Wireless profile file(s)” to be written to the current directory.  Here is the contents of the Wireless Network Connection file for my GoldFish WiFi network.

<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
    <name>GoldFish</name>
    ....
    ....
    ....
            <sharedKey>
                <keyType>passPhrase</keyType>
                <protected>false</protected>
                <keyMaterial>T-Man Colt 1911 These Boy Billards</keyMaterial>
            </sharedKey>
    ....
    ....
    ....
</WLANProfile>

 

My GoldFish WiFi is highlighted in blue above, between the <keyMaterial> fields.
ie. “T-Man Colt 1911 These Boy Billards”

Setting up wireless IP cameras–some further bits

Back on the 5th December, I wrote about how to setup outdoor wireless surveillance cameras.  I’ve had a couple emails asking questions, so here are the replies:

What do you get in the box?

WiFi Camera Components

  • WiFi Camera
  • WiFi Aerial
  • 110/240v –> 12v power supply, with US plug-type
  • US to Australia power adapter.
  • Ethernet cable
  • Mounting base & screws
  • Installation/instruction manual CD.

What was the easiest way to adjust the “camera view”?

Netbook and camera

I used a portable (WiFi-enabled) netbook to determine camera placement and to also help with final camera view adjustment.

Run into any unexpected problems?

Two:

  1. The WiFi cameras “reset” themselves every 4-7 days.  As both cameras reset at the same time, my guess is that the power to the house “drops” out.  A UPS will fix that.
     
  2. If you enable the “motion alarm”, and then hang clothes on the clothes line, do not be surprised if you receive 100’s of emails.  This is because the clothes on the clothes line are swaying because of wind.
    Now I remember to disable the motion alarm before I place clothes on the line.