Geolocating 802.11 access points by MAC address using Google Geolocation API

♀尐吖头ヾ 提交于 2019-11-30 19:52:51
<?php

$mac = $_SERVER['argv'][1];


$postData = '{
    "version": "1.1.0", 
    "wifi_towers": [{
        "mac_address": "' . $mac . '", 
        "ssid": "0", 
        "signal_strength":-72
    }]
}';

$opts = array(
  'http'=>array(
    'method' => "POST",
    'header'  => 'Content-type: application/x-www-form-urlencoded',
    'content' => $postData
  )
);


$response = file_get_contents(
    'http://www.google.com/loc/json', 
    false, 
    stream_context_create($opts)
);

$loc = json_decode($response, true);

echo $loc['location']['latitude'];
echo ',';
echo $loc['location']['longitude'];

Command line usage:

php geo.php "mac addy here"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!