class Rex::Google::Geolocation
@example
g = Rex::Google::Geolocation.new g.add_wlan("00:11:22:33:44:55", "example", -80) g.fetch! puts g, g.google_maps_url
Constants
- GOOGLE_API_URI
Attributes
accuracy[RW]
latitude[RW]
longitude[RW]
Public Class Methods
new()
click to toggle source
# File lib/rex/google/geolocation.rb, line 20 def initialize @uri = URI.parse(URI.encode(GOOGLE_API_URI)) @wlan_list = [] end
Public Instance Methods
add_wlan(mac, ssid = nil, signal_strength = nil)
click to toggle source
Add an AP to the list to send to Google
when {#fetch!} is called.
Turns out Google's API doesn't really care about ESSID or signal strength as long as you have BSSIDs. Presumably adding them will make it more accurate? Who knows.
@param mac [String] in the form “00:11:22:33:44:55” @param ssid [String] ESSID associated with the mac @param signal_strength [String] a thing like
# File lib/rex/google/geolocation.rb, line 55 def add_wlan(mac, ssid = nil, signal_strength = nil) @wlan_list.push(URI.encode("mac:#{mac.upcase}|ssid:#{ssid}|ss=#{signal_strength.to_i}")) end
fetch!()
click to toggle source
Ask Google's Maps API for the location of a given set of BSSIDs (MAC addresses of access points), ESSIDs (AP names), and signal strengths.
# File lib/rex/google/geolocation.rb, line 27 def fetch! @uri.query << @wlan_list.take(10).join("&wifi=") request = Net::HTTP::Get.new(@uri.request_uri) http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true response = http.request(request) if response && response.code == '200' results = JSON.parse(response.body) self.latitude = results["location"]["lat"] self.longitude = results["location"]["lng"] self.accuracy = results["accuracy"] else msg = "Failure connecting to Google for location lookup." msg += " Code #{response.code} for query #{@uri}" if response fail msg end end
google_maps_url()
click to toggle source
# File lib/rex/google/geolocation.rb, line 59 def google_maps_url "https://maps.google.com/?q=#{latitude},#{longitude}" end
to_s()
click to toggle source
# File lib/rex/google/geolocation.rb, line 63 def to_s "Google indicates the device is within #{accuracy} meters of #{latitude},#{longitude}." end