Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Geolocation wifi Scanner and Finder

0.00/5 (No votes)
2 Apr 2015 1  
Written in C# and VS2010 as a class libary to be used in your own project.

Introduction

The project scans wifi networks in the area to retrieve names, speeds and MAC addresses that can then be used to make a geo-location request to Google's servers and was written using C# in VS2010 to produce a class library.

A service is provided to poll for new wifi connects every ten seconds or so and these connections are returned in a collection ready to be used as you like or saved as an XML table by calling Save(XMLFileName); so that the data can be used by other programs.

Background

I was concerned with just what Google was uploading when someone in the area made a geo-location request and how my data was being used plus I wanted to build geo-location into the browser I have been working on.

Using the Code

Included is the full source code for the project along with output class library that has been compiled as a DLL and all the calls to the library use static methods as shown below to make the code simple to use. Sample code is provided in the file Sample.cs.

Full credit given to NativeWifi who produces some of the open source Windows API calls used in the project .

C#
//
WifiScanner.WifiConnection.Start(10000);//Poll wifi connections every ten seconds
Thread.Sleep(30000);                    //Wait for three polls to complete
WifiScanner.WifiConnection.Stop();      //stop polling for new connections
string Json=WifiScanner.WifiConnection.GetGeoLocation(); //Ask Google for the json string
WifiScanner.WifiConnection.Clear();     //Clear any internal data
//

Viewing the request sent to Google from your browser is not easy since it uses encrypted SSL packets but a little trick that works in Firefox is to type "About:config" into the URL and then search for "Google" and to then edit the Geo.Wifi.Url value from being HTTPS to HTTP and to then make a geo-location request from the browser that uses a proxy server that allows you to inspect the outbound HTTP request header and XML post data.

C#
//
POST /geolocation/v1/geolocate?key=abcdFakeKey HTTP/1.1
Host: www.xgoogleapis.com
Connection: keep-alive
Content-Length: 662
Pragma: no-cache
Cache-Control: no-cache
Content-Type: application/json
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Accept-Encoding: gzip, deflate

{"wifiAccessPoints":[{"age":1,"macAddress":"11-1d-aa-a6-13-38",
"signalStrength":-43},{"age":1,"macAddress":"11-1d-aa-a6-13-33",
"signalStrength":-44},{"age":1,"macAddress":"3a-b1-db-2c-53-a5",
"signalStrength":-56},{"age":1,"macAddress":"16-2d-26-35-d5-a8",
"signalStrength":-61},{"age":1,"macAddress":"11-21-14-d6-ee-82",
"signalStrength":-66},{"age":1,"macAddress":"16-21-14-d6-ee-82",
"signalStrength":-66},{"age":1,"macAddress":"e4-f4-c6-86-26-b8",
"signalStrength":-66},{"age":1,"macAddress":"1a-21-14-d6-ee-82",
"signalStrength":-68},{"age":1,"macAddress":"e4-f4-c6-86-26-b3",
"signalStrength":-68},{"age":1,"macAddress":"84-1b-5e-bb-2a-b8",
"signalStrength":-86}]}
//

This is my first project that I have released on CodeProject but keep watching if you want a fully working remote desktop or want to learn how to get "Play to" working in Windows without having to open lots of ports or to have all the correct Windows services running.

Enjoy!

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