Created
October 19, 2017 15:03
-
-
Save LoganRickert/4c4d66c29dd844abcd385f2234d84a11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import os | |
from platform import system as os_name | |
import requests | |
from colorama import init, Fore, Style | |
def printer(request_json, line_width): | |
""" Print the main body of the UI """ | |
print('Lookup Information For : ' + Fore.MAGENTA + request_json['query'] + Style.RESET_ALL) | |
print('\nGeneral IP Information') | |
print(''.ljust(line_width)+ 'ISP: ' + request_json['isp']) | |
print(''.ljust(line_width)+ 'AS number / name: ' + request_json['as']) | |
print(''.ljust(line_width)+ 'Organization name: ' + request_json['org']) | |
print('\nGeolocation IP Information') | |
print(''.ljust(line_width)+ 'Latitude: ' + str(request_json['lat'])) | |
print(''.ljust(line_width)+ 'Longitude: ' + str(request_json['lon'])) | |
print(''.ljust(line_width)+ 'Country: ' + request_json['country'] | |
+ ' ' + request_json['countryCode']) | |
print(''.ljust(line_width)+ 'Region: ' + request_json['regionName'] | |
+ ' ' + request_json['region']) | |
print(''.ljust(line_width)+ 'City: ' + request_json['city']) | |
print(''.ljust(line_width)+ 'Zip / Postcode: ' + request_json['zip']) | |
print(''.ljust(line_width)+ 'Timezone: ' + request_json['timezone'] + '\n') | |
line_width = 10 | |
address = "130.108.85.16" | |
def lookup(address): | |
try: | |
if address: | |
request = requests.get('http://ip-api.com/json/'+address) | |
else: | |
request = requests.get('http://ip-api.com/json/') | |
request_json = request.json() | |
if request_json['status'] == 'success': | |
# printer(request_json, line_width) | |
return request_json | |
elif request_json['status'] == 'fail': | |
print('Error:') | |
print(''.ljust(line_width)+ 'Query sent: ' + Fore.MAGENTA + request_json['query'] + Style.RESET_ALL) | |
print(''.ljust(line_width)+ 'Message: ' + request_json['message']) | |
else: | |
print('Error: ' + str(request.status_code)) | |
return False | |
except requests.exceptions.RequestException as error: | |
print('Error: ' + str(error)) | |
print('\n Check your internet connection') | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment