Click here to Skip to main content
15,884,009 members
Articles / Programming Languages / C# 3.5
Tip/Trick

Geolocation wifi Scanner and Finder

Rate me:
Please Sign up or sign in to vote.
5.00/5 (9 votes)
2 Apr 2015CPOL2 min read 33.2K   1.5K   20   6
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
Old dog that is tired of learning new tricks when the new dish they are cooking never tastes quite so good as the old one.

Comments and Discussions

 
QuestionAccuracy Pin
Tom Ragsdale317-Jul-19 1:53
Tom Ragsdale317-Jul-19 1:53 
Questiongood work Pin
Jhone Menezes10-Mar-17 20:04
Jhone Menezes10-Mar-17 20:04 
GeneralMy vote of 5 Pin
D V L6-Nov-15 22:53
professionalD V L6-Nov-15 22:53 
Questionverified Pin
ARCHARRY3-Apr-15 9:31
ARCHARRY3-Apr-15 9:31 
QuestionBattery Drain Pin
Vasudevan Deepak Kumar3-Apr-15 2:38
Vasudevan Deepak Kumar3-Apr-15 2:38 
AnswerRe: Battery Drain Pin
Dr Gadgit5-Apr-15 8:39
Dr Gadgit5-Apr-15 8:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.