5,442,164 members and growing! (16,746 online)
Email Password   helpLost your password?
Desktop Development » Desktop Gadgets » General     Intermediate

A Vista Wireless Network Scanner

By Charles Putney

A NetStumbler (sort of) for Vista
C#, .NET, Vista, Windows, Visual Studio, Dev

Posted: 22 Jun 2007
Updated: 26 Jun 2007
Views: 57,389
Bookmarked: 34 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
8 votes for this Article.
Popularity: 3.40 Rating: 3.76 out of 5
1 vote, 12.5%
1
0 votes, 0.0%
2
1 vote, 12.5%
3
3 votes, 37.5%
4
3 votes, 37.5%
5

Screenshot - WifiScanner1.gif

Introduction

I recently got a new notebook and was routinely transferring all of my old, favourite utilities to it when I found that NetStumbler would not work with Vista. I saw some references to a poor-man's version with the following command line:

netsh wlan show networks mode=bssid

I decided to put it in a window, so here is my effort. For Microsoft documentation on netsh, see Windows Netsh.

The code

A timer on the Form calls the Scan() function every two seconds. The Scan() function first uses the Process() class to execute the netsh command with the command line parameters:

Process proc = new Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = "netsh";
proc.StartInfo.Arguments = "wlan show networks mode=bssid";
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
output = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();

The output is then parsed line-by-line to build an array of currently active networks. This is presented in a listView using the MAC Address as the item text with sub-items for the rest of the information. Discovered networks that are not already in the listView are found using:

ListViewItem SearchItem = new ListViewItem();
SearchItem = listView1.FindItemWithText(Networks[i, 0]);
if (SearchItem == null)
{
    // New discovery - add it to the list

Any networks already in the listView are updated. The signal level icon is generated by bitmaps on the listView:

int SignalInt = Convert.ToInt32(Networks[i, 3].TrimEnd(' ').TrimEnd('%'));
if (SignalInt > 50) listView1.Items[listView1.Items.Count-1].ImageIndex = 0;
else . . .

The coloured icons represent the signal levels as:

Green Dot Greater than 50% Signal Level

Yellow Dot 41% to 50% Signal Level

Orange Dot 31% to 40% Signal Level

Red Dot 21% to 30% Signal Level

Dark Red Dot 1% to 20% Signal Level

Grey Dot No Signal

Points of interest

One annoyance with the listView control was flicker. Every Update() or Refresh() caused the whole list to be cleared and re-written. I used a tip from Don Koster and added his listViewNF class. Using this listViewNF class stopped the flicker by redrawing only the changed areas.

class ListViewNF : System.Windows.Forms.ListView
{
    public ListViewNF()
    {
        //Activate double buffering

        this.SetStyle(ControlStyles.OptimizedDoubleBuffer | 
            ControlStyles.AllPaintingInWmPaint, true);

        //Enable the OnNotifyMessage event so we get a chance to filter out

        // Windows messages before they get to the Form's WndProc

        this.SetStyle(ControlStyles.EnableNotifyMessage, true);
    }

    protected override void OnNotifyMessage(Message m)
    {
        //Filter out the WM_ERASEBKGND message

        if (m.Msg != 0x14)
        {
            base.OnNotifyMessage(m);
        }
    }

Known issues

The netsh command can sometimes be slow at updating the real network state. If a network is connected, it seems that the signal level displayed by netsh is not updated. Being connected also seems to alter the signal level of the connected network and other networks. When a connected network is turned off, it can take more than a minute for netsh -- or possibly this is a driver issue -- to remove the network from the output. Turning the wireless off and back on seems to force a new signal level. Also, sometimes the netsh command seems to change signal levels at every update. Once it gets in this mode, it will update the signal level for every command when operating on main power, but if it's operating on battery power it doesn't! The normal signal update interval seems to be one minute. I tested this using a Dell 640m notebook with an Intel 3945ABG wireless adapter.

History

  • June 23, 2007: New article.
  • June 24, 2007: Whoops! Bitmaps were not included in the demo project. This is fixed now.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Charles Putney


My first experiences with computing was with a Bendix G15 drum computer at Carnegie Mellon. More followed with CDC G20, IBM 360, Univac 1108, Apple II, and 386XXX. I have done microprocessor programming and design for 6502, Z80, and 8051. I have moved to C# now and am still struggling to understand this. My career has been in engineering starting with Texas Instruments and continuing with Becton Dickinson, Dataproducts, Hitachi Printing Solutions and now retired from Ricoh Printing Systems Europe.
Location: Ireland Ireland

Other popular Desktop Gadgets articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 32 (Total in Forum: 32) (Refresh)FirstPrevNext
Subject  Author Date 
QuestionPossibility to Associate?membersud_net5:03 27 Aug '08  
AnswerRe: Possibility to Associate?memberCharles Putney22hrs 51mins ago 
QuestionWiFi in Javamembermulllllen23:50 17 Aug '08  
AnswerRe: WiFi in JavamemberCharles Putney7:11 20 Aug '08  
GeneralWifi in C++ or C#memberTenketsu23:40 17 Jul '08  
GeneralRe: Wifi in C++ or C#memberCharles Putney8:00 19 Jul '08  
GeneralFeature Request: Averagesmemberdubbele onzin20:03 13 Nov '07  
GeneralHi Mr. Putneymemberxxxkrogoth11:33 1 Sep '07  
GeneralRe: Hi Mr. PutneymemberCharles Putney3:23 6 Sep '07  
GeneralHi Mr. PutneymemberLars Westergren23:43 26 Mar '08  
Generalget this function under windows xp~~membersteven_xiangmin21:55 27 Aug '07  
GeneralRe: get this function under windows xp~~memberCharles Putney3:16 6 Sep '07  
GeneralManaged Native Wifi APImembernormanr5:45 7 Aug '07  
GeneralRe: Managed Native Wifi APImembernormanr22:17 9 Aug '07  
GeneralVistumblermemberACalcutt10:05 24 Jul '07  
GeneralRe: VistumblermemberCharles Putney12:16 24 Jul '07  
GeneralNetstumbler on VistamemberRC_Knight5:00 24 Jul '07  
GeneralMost columns are empty?!memberthepiotr22:32 20 Jul '07  
GeneralRe: Most columns are empty?!memberCharles Putney13:36 23 Jul '07  
GeneralRe: Most columns are empty?!memberthepiotr21:30 23 Jul '07  
GeneralRe: Most columns are empty?!memberRauk10:04 11 Sep '07  
GeneralRe: Most columns are empty?!memberCharles Putney11:55 11 Sep '07  
Generallanguage issuememberrudy_adamse12:29 6 Jul '07  
GeneralRe: language issuememberCharles Putney7:20 9 Jul '07  
GeneralProblems using MAC address as the identifiermemberPaulCan19:57 25 Jun '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 26 Jun 2007
Editor: Genevieve Sovereign
Copyright 2007 by Charles Putney
Everything else Copyright © CodeProject, 1999-2008
Web17 | Advertise on the Code Project