pry0cc
(Leader & Offsec Engineer & Forum Daddy)
July 30, 2016, 10:03pm
1
Welcome back command-line ninjas, I wanted to take a small break from Trixβ with Linux and decided to write myself a tool. I noticed nothing was really out that would give you a comprehensive overview of an IP, which is awesome for Recon, and being totally 1337
This tool is written in ruby and utilises freegeoip.net , Google maps, and wttr.in. You can download the whole script here so that you donβt have to mess around with copy and pasting
Keep in mind you will need Mechanize installed, to install this ruby gem, just run gem install mechanize
and you should be good to go!
Heres the script:
#!/usr/bin/env ruby
require 'json'
require 'mechanize'
require 'rubygems'
require 'open-uri'
puts "Looking up #{ARGV[0]}"
agent = Mechanize.new
data = agent.get("http://freegeoip.net/json/#{ARGV[0]}").body
json = JSON.parse(data)
agent.user_agent = "curl/7.50.0"
weather = agent.get("http://wttr.in/#{json["city"]}").body.split("\n")
puts "Country Code: " + json["country_code"]
puts "Country: " + json["country_name"]
puts "Region Code: " + json["region_code"]
puts "Region Name: " + json["region_name"]
puts "City: " + json["city"]
puts "Zip Code: " + json["zip_code"]
puts "Time Zone: " + json["time_zone"]
puts "Metro Code: " + json["metro_code"].to_s
puts "Google Maps: https://www.google.com/maps?z=12&t=m&q=loc:#{json["latitude"]}+#{json["longitude"]}"
puts "Weather right now: "
puts weather[1..6]
puts ""
Let me explain how this script works. When you run it, you supply it 1 argument, the IP address or hostname of the person/device you want to track. And it returns the estimated address, relevant Google Maps link, and current weather.
Hope you enjoyed this! I will be using this a lot Cheers!
pry0cc
12 Likes
n3xUs
July 30, 2016, 11:05pm
2
I havenβt tried it out myself, but dudeβ¦ it looks AWESOME!
1 Like
oaktree
(oaktree)
July 31, 2016, 1:06am
3
When I tried to use it, it hung pretty hard.
Seems pretty dang awesome mate!
1 Like
pry0cc
(Leader & Offsec Engineer & Forum Daddy)
July 31, 2016, 7:19am
5
Oh yeah? Did it run at all? Iβve tested it with ruby 2.3.0
1 Like
ivlb
(Monkey Wrench)
August 3, 2016, 10:52am
6
Py3 rewrite, idea credit goes to @pry0cc
The only difference is that it displays full weather info (too lazy to crop).
You can download the script from pastebin .
--------------------------------------------------
longitude: -122.0574
latitude: 37.4192
region_code: CA
country_name: United States
country_code: US
city: Mountain View
metro_code: 807
ip: 216.58.212.142
region_name: California
time_zone: America/Los_Angeles
zip_code: 94043
Weather for City: Mountain View, United States of America
\ / Partly Cloudy
_ /"".-. 16 Β°C
\_( ). β 7 km/h
/(___(__) 16 km
0.0 mm
βββββββββββββββ
ββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββ€ Wed 03. Aug βββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β Morning β Noon ββββββββ¬βββββββ Evening β Night β
ββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ€
β \ / Partly Cloudy β \ / Sunny β \ / Sunny β \ / Clear β
β _ /"".-. 15 β 17 Β°C β .-. 20 β 21 Β°C β .-. 22 β 23 Β°C β .-. 16 Β°C β
β \_( ). β 8 β 9 km/h β β ( ) β β 10 β 12 km/h β β ( ) β β 21 km/h β β ( ) β β 10 β 11 km/h β
β /(___(__) 10 km β `-β 10 km β `-β 10 km β `-β 10 km β
β 0.0 mm | 0% β / \ 0.0 mm | 0% β / \ 0.0 mm | 0% β / \ 0.0 mm | 0% β
ββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ
βββββββββββββββ
ββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββ€ Thu 04. Aug βββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β Morning β Noon ββββββββ¬βββββββ Evening β Night β
ββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ€
β \ / Partly Cloudy β \ / Sunny β \ / Sunny β Overcast β
β _ /"".-. 12 β 15 Β°C β .-. 18 β 19 Β°C β .-. 24 β 25 Β°C β .--. 19 Β°C β
β \_( ). β 9 β 10 km/h β β ( ) β β 12 β 13 km/h β β ( ) β β 18 β 21 km/h β .-( ). β 11 β 13 km/h β
β /(___(__) 10 km β `-β 10 km β `-β 10 km β (___.__)__) 10 km β
β 0.0 mm | 0% β / \ 0.0 mm | 0% β / \ 0.0 mm | 0% β 0.0 mm | 0% β
ββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ
βββββββββββββββ
ββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββ€ Fri 05. Aug βββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β Morning β Noon ββββββββ¬βββββββ Evening β Night β
ββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ€
β \ / Sunny β \ / Sunny β \ / Sunny β \ / Clear β
β .-. 18 Β°C β .-. 18 β 19 Β°C β .-. 21 β 22 Β°C β .-. 15 β 16 Β°C β
β β ( ) β β 9 β 11 km/h β β ( ) β β 6 β 14 km/h β β ( ) β β 19 km/h β β ( ) β β 8 β 12 km/h β
β `-β 10 km β `-β 10 km β `-β 10 km β `-β 10 km β
β / \ 0.0 mm | 0% β / \ 0.0 mm | 0% β / \ 0.0 mm | 0% β / \ 0.0 mm | 0% β
ββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ
https://www.google.com/maps?z=12&t=m&q=loc:@37.4192,-122.0574
--------------------------------------------------
#!/usr/bin/python3
import requests
import argparse
from html.parser import HTMLParser
class DirtyWttrParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.start = False
self.stop = False
self.weather = str()
def is_doable(self):
return self.start + self.stop
def handle_starttag(self, tag, attrs):
if tag == 'pre':
self.start = True
def handle_endtag(self, tag):
if tag == 'pre':
self.stop = True
def handle_data(self, data):
if self.is_doable() == 1:
self.weather += data
def get_data(url, type):
try:
r = requests.get(url)
except Exception as e:
print("[-] Failed fetching data")
print(e)
return
if type == 'json':
return r.json()
elif type == 'html':
return r.text
def main():
# parse script args (IP)
argsp = argparse.ArgumentParser()
argsp.add_argument("ip", help="IP to check", type=str)
args = argsp.parse_args()
# init components
ip_to_check = args.ip
url_geoip = 'http://freegeoip.net/json/'
url_wttr = 'http://wttr.in/'
url_maps = 'https://www.google.com/maps?z=12&t=m&q=loc:@'
parser = DirtyWttrParser()
# get info
ip_info = get_data(url_geoip + ip_to_check, 'json')
parser.feed(get_data(url_wttr + '@' + ip_to_check, 'html'))
# display info
print('-' * 50)
for k, v in ip_info.items():
print('{}: {}'.format(k, v))
print(parser.weather)
print('{}{},{}'.format(url_maps, ip_info['latitude'], ip_info['longitude']))
print('-' * 50)
if __name__ == '__main__':
main()
4 Likes
pry0cc
(Leader & Offsec Engineer & Forum Daddy)
August 3, 2016, 12:01pm
7
Awesome! You know cropping is easy.
Do a split on newline, and then just print array item 0-6.
1 Like
pry0cc
(Leader & Offsec Engineer & Forum Daddy)
Closed
January 21, 2018, 12:30am
8
This topic was automatically closed after 30 days. New replies are no longer allowed.