Wifi Geolocator

Da, voljeli bi vidjeti što ste uspjeli napraviti? Od 3D modela i zvukova skroz do trailera i prezentacija vaših igara/aplikacija.
Post Reply
User avatar
UDP11
Obama s Trešnjevke
Posts: 657
Joined: Thu Nov 06, 2008 2:38 pm
Smallest prime number bigger than 20: 23

Wifi Geolocator

Post by UDP11 » Mon Jun 06, 2011 11:52 pm

Ako imate wlan karticu sa ovim programcicom mozete naci gdje se nalazi, pogađa sa tolikom točnošću da je meni uspio skužiti u ulicu i broj ulice gdje se trenutno nalazim.

Bin:
U attachmentu.
Source:

Code: Select all

#include <windows.h>
#include <wlanapi.h>
#include <iostream>
#include <string>
#include <sstream>
#include <wininet.h>
#include <vector>
using namespace std;


#define HANDLE_ERROR -60
#define ENUM_ERROR -59;
#define DEVICE_ERROR -58

#pragma comment(lib,"wlanapi.lib");
#pragma comment(lib,"wininet.lib");

void SplitString(const string& s, char c,vector<string>& v);

int main(int argc, char** argv)
{
	/*	1 - Client version for Windows XP with SP3 and Wireless LAN API for Windows XP with SP2.
	
	2 - Client version for Windows Visxta and Windows Server 2008 and Above
	*/

	DWORD version = 2;
	HANDLE hClientHandle = NULL;
	PWLAN_INTERFACE_INFO_LIST pEnum = NULL;
	bool foundAdapter = false;
	GUID interfaceGUID;
	PWLAN_BSS_LIST pWlanBssList = NULL;
	string JSON = "{""\"host""\":""\"KBD""\",""\"radio_type""\":""\"unknown""\",""\"request_address""\":true,""\"version""\":""\"1.1.0""\",""\"wifi_towers""\":[";
	stringstream ss;
	if(WlanOpenHandle(version,0,&version,&hClientHandle) != ERROR_SUCCESS)
	{
		cerr << "Error: Could not open WLAN handle" << endl;
		return HANDLE_ERROR;
	}

	if(hClientHandle == 0)
	{
		cerr << "Error: Invalid client handle." << endl;
		return HANDLE_ERROR;
	}
	
	if(WlanEnumInterfaces(hClientHandle,0,&pEnum) != ERROR_SUCCESS)
	{
		cerr << "Error: Could not enumerate interfaces." << endl;
		return ENUM_ERROR;
	}


	/*
		  wlan_interface_state_not_ready               = 0,
		  wlan_interface_state_connected               = 1,
		  wlan_interface_state_ad_hoc_network_formed   = 2,
		  wlan_interface_state_disconnecting           = 3,
		  wlan_interface_state_disconnected            = 4,
		  wlan_interface_state_associating             = 5,
		  wlan_interface_state_discovering             = 6,
		  wlan_interface_state_authenticating          = 7 
	*/

	for(byte i=0;i<pEnum->dwNumberOfItems;i++)
	{
		cout << "OK" << endl;
		if(pEnum->InterfaceInfo[i].isState != wlan_interface_state_not_ready)
		{
			interfaceGUID = pEnum->InterfaceInfo[i].InterfaceGuid;
			foundAdapter = true;
			break;
		}
		
	}

	if(foundAdapter != true)
	{
		cerr << "Error: Could not find compatible WLAN device." << endl;
		return DEVICE_ERROR;
	}

	if(WlanGetNetworkBssList(hClientHandle,&interfaceGUID,NULL,dot11_BSS_type_any,0,0,&pWlanBssList) != ERROR_SUCCESS)
	{
		cerr << "Error: Could not get network list." << endl;
		return DEVICE_ERROR;
	}

	for(unsigned char i=0; i < pWlanBssList->dwNumberOfItems; i++)
	{
		ss << ("{""\"mac_address""\":""\"");
		if(MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[0],1,1) <10)
		ss << "0" << MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[0],1,1) <<"-";
		else
		ss << hex << MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[0],1,1) << "-";
		if(MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[1],1,1) <10)
		ss << "0" << MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[1],1,1) <<"-";
		else
		ss << hex << MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[1],1,1) << "-";
		if(MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[2],1,1) <10)
		ss << "0" << MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[2],1,1) <<"-";
		else
		ss << hex << MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[2],1,1) << "-";
		if(MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[3],1,1)<10)
		ss << "0" << MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[3],1,1) <<"-";
		else
		ss << hex << MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[3],1,1) << "-";
		if(MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[4],1,1) <10)
		ss << "0" << MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[4],1,1) <<"-";
		else
		ss << hex << MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[4],1,1) << "-";
		if(MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[5],1,1) < 10)
		ss << "0" << MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[5],1,1) << "\"";
		else
		ss << hex << MulDiv(pWlanBssList->wlanBssEntries[i].dot11Bssid[5],1,1) << "\"";
		ss << ",";
		ss << "\"signal_strength""\":";
		ss << dec << pWlanBssList->wlanBssEntries[i].lRssi;
		ss << ",";
		ss << "\"ssid""\":""\"";
		ss << pWlanBssList->wlanBssEntries[i].dot11Ssid.ucSSID;
		ss << """\"},"; 
	}

	JSON.append(ss.str());
	JSON = JSON.substr(0, JSON.length() - 1);
	JSON.append("]}"); 
	WlanCloseHandle(hClientHandle,NULL);
	WlanFreeMemory(pEnum);
	WlanFreeMemory(pWlanBssList);


	
	HINTERNET internet;
	HINTERNET request;
	HINTERNET connect;

	string blah;
	char *a=new char[JSON.size()+1];
	a[JSON.size()]=0;
	memcpy(a,JSON.c_str(),JSON.size());
	DWORD bytesRead;
	char d;
	string location;
	stringstream locfuck;

	internet = InternetOpen(L"",0,0,0,0);
	connect = InternetConnect(internet,L"www.google.com",80,0,0,3,0,0);
	request = HttpOpenRequest(connect,L"POST",L"/loc/json",L"HTTP/1.1",0,0,0,0);
	if(HttpSendRequest(request,0,0,a,strlen(a)))
	{
	while(InternetReadFile(request,&d,1,&bytesRead))
	{
		if(bytesRead==0)break;
		locfuck << d;
	}
	}
	InternetCloseHandle(internet);
	InternetCloseHandle(request);
	InternetCloseHandle(connect);

	vector<string>data;
	string latitude,longitude,country,ccode,region,city,street,streetnum;
	location.append(locfuck.str());
	SplitString(location,',',data);
	latitude = data[0].substr(24,data[0].length()-1);
	longitude = data[1].substr(12,data[1].length()-1);
	country = data[2].substr(22,data[2].length()-1);
	ccode = data[3].substr(15,data[3].length()-1);
	region = data[4].substr(9,data[4].length()-1);
	city = data[5].substr(7,data[5].length()-1);
	street = data[6].substr(9,data[6].length()-1);
	streetnum = data[7].substr(16,data[7].length()-4);
	cout << latitude << endl;
	cout << longitude << endl;
	cout << country << endl;
	cout << ccode << endl;
	cout << region << endl;
	cout << city << endl;
	cout <<street << endl;
	cout << streetnum << endl;
	//	for(int i=0;i<data.size();i++)
	//cout << data[i] << endl;;
	string lol = "http://wikimapia.org/#lat="+latitude+"&lon="+longitude+"&z=21&l=0&m=b";
	ShellExecuteA(NULL, "open", lol.c_str(), NULL, NULL, SW_SHOWNORMAL);
	return 0;
}



void SplitString(const string& s, char c,
           vector<string>& v) {
   string::size_type i = 0;
   string::size_type j = s.find(c);
   while (j != string::npos) {
      v.push_back(s.substr(i, j-i));
      i = ++j;
      j = s.find(c, j);
      if (j == string::npos)
         v.push_back(s.substr(i, s.length( )));
   }
}
You do not have the required permissions to view the files attached to this post.
Image

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests