Class: Rex::Google::Geolocation
- Inherits:
-
Object
- Object
- Rex::Google::Geolocation
- Defined in:
- lib/rex/google/geolocation.rb
Overview
Constant Summary collapse
- GOOGLE_API_URI =
"https://maps.googleapis.com/maps/api/browserlocation/json?browser=firefox&sensor=true&"
Instance Attribute Summary collapse
-
#accuracy ⇒ Object
Returns the value of attribute accuracy.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
Instance Method Summary collapse
-
#add_wlan(mac, ssid = nil, signal_strength = nil) ⇒ Object
Add an AP to the list to send to Google when #fetch! is called.
-
#fetch! ⇒ Object
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.
- #google_maps_url ⇒ Object
-
#initialize ⇒ Geolocation
constructor
A new instance of Geolocation.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Geolocation
Returns a new instance of Geolocation.
20 21 22 23 |
# File 'lib/rex/google/geolocation.rb', line 20 def initialize @uri = URI.parse(URI.encode(GOOGLE_API_URI)) @wlan_list = [] end |
Instance Attribute Details
#accuracy ⇒ Object
Returns the value of attribute accuracy.
16 17 18 |
# File 'lib/rex/google/geolocation.rb', line 16 def accuracy @accuracy end |
#latitude ⇒ Object
Returns the value of attribute latitude.
17 18 19 |
# File 'lib/rex/google/geolocation.rb', line 17 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
18 19 20 |
# File 'lib/rex/google/geolocation.rb', line 18 def longitude @longitude end |
Instance Method Details
#add_wlan(mac, ssid = nil, signal_strength = nil) ⇒ Object
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.
55 56 57 |
# 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! ⇒ Object
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.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 ⇒ Object
59 60 61 |
# File 'lib/rex/google/geolocation.rb', line 59 def google_maps_url "https://maps.google.com/?q=#{latitude},#{longitude}" end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/rex/google/geolocation.rb', line 63 def to_s "Google indicates the device is within #{accuracy} meters of #{latitude},#{longitude}." end |