Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



 1076

Python Ip Lookup Tool

by MrBoi47 - 01 May, 2022 - 09:55 AM
This post is by a banned member (MrBoi47) - Unhide
MrBoi47  
Registered
33
Posts
6
Threads
2 Years of service
#1
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 ") 
This post is by a banned member (TimeChangeEverything) - Unhide
39.925
Posts
13.027
Threads
5 Years of service
#2
(01 May, 2022 - 09:55 AM)MrBoi47 Wrote: Show More
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 ") 

I will try this
[Image: 81QoXii.gif]
[Image: PUm4fxA.gif]

 
                                                      
Above Services are Paid Advertisement

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)