OP 01 May, 2022 - 09:55 AM
I coded an IP lookup tool because I had nothing to do :)
Code:
import requests, webbrowser, re
yourip=requests.get('https://api64.ipify.org?format=json').json()
print("Your IP: "+yourip["ip"])
print("")
ipaddress=str(input("Target IP: "))
pattern=r"([01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.([01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.([01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.([01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])"
try:
if re.match(pattern, ipaddress) or ipaddress.lower()=="me":
print("")
if ipaddress.lower()=="me":
response = requests.get(f'https://ipapi.co/{yourip["ip"]}/json/').json()
else:
response = requests.get(f'https://ipapi.co/{ipaddress}/json/').json()
looklist=("city", "region", "region_code", "country_name", "country_code","", "org", "asn", "", "country_tld", "country_calling_code", "currency", "currency_name", "timezone",)
def lookup(x):
x=x+": "+response.get(x)
print(x)
n=0
while n < len(looklist):
if looklist[n]=="":
print("")
n+=1
else:
lookup(looklist[n])
n+=1
print("")
asnvar=input("ASN Search? (Y/N) ").upper()
if asnvar=="Y":
webbrowser.open("https://bgp.he.net/"+response.get("asn"))
done=input("Press enter to finish ")
else:
done=input("Not a valid IP address ")
except TypeError:
done=input("IP address not in service ")