├── Readme.md └── main.py /Readme.md: -------------------------------------------------------------------------------- 1 | # Get info by IP or URL 2 | You can set IP address or host to get IP information 3 | 4 | # Info by IP 5 | Example: 6 | 7 | Input: 176.31.84.249 8 | 9 | Output: 10 | ``` 11 | [IP] : 176.31.84.249 12 | [Country] : France 13 | [City] : Gravelines 14 | [Organization] : Baiocco Stephane 15 | [Region name] : Hauts-de-France 16 | [Lat] : 50.9871 17 | [Lon] : 2.12554 18 | ``` 19 | 20 | # Info by hostname 21 | Example: 22 | 23 | Input: google.com 24 | 25 | Output: 26 | ``` 27 | Hostname: google.com 28 | [IP] : 74.125.131.138 29 | [Country] : United States 30 | [City] : Mountain View 31 | [Organization] : Google LLC 32 | [Region name] : California 33 | [Lat] : 37.422 34 | [Lon] : -122.084 35 | ``` 36 | 37 | # Author 38 | Pavel Dat 39 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from pyfiglet import Figlet 3 | 4 | import socket 5 | 6 | def get_info_by_ip(ip='127.0.0.1'): 7 | try: 8 | response = requests.get(url=f'http://ip-api.com/json/{ip}').json() 9 | 10 | data = { 11 | '[IP]' : response.get('query'), 12 | '[Country]' : response.get('country'), 13 | '[City]' : response.get('city'), 14 | '[Organization]' : response.get('org'), 15 | '[Region name]' : response.get('regionName'), 16 | '[Lat]' : response.get('lat'), 17 | '[Lon]' : response.get('lon') 18 | } 19 | 20 | for k, v in data.items(): 21 | print(f'{k} : {v}') 22 | 23 | except requests.exceptions.ConnectionError: 24 | return 'Check your connection' 25 | 26 | def get_ip_by_hostname(hostname='google.com'): 27 | try: 28 | print(f'Hostname: {hostname}') 29 | get_info_by_ip(ip=socket.gethostbyname(hostname)) 30 | 31 | except socket.gaierror as error: 32 | return f'Invalid Hostname. Error: {error}' 33 | 34 | 35 | def main(): 36 | preview = Figlet(font='slant') 37 | print(preview.renderText('Made by Pavel Dat')) 38 | resp = input('Enter IP or URL: ') 39 | 40 | if len(resp) == 0: 41 | print("The input is empty. Try again") 42 | main() 43 | elif resp.count('.') == 3: 44 | get_info_by_ip(ip=resp) 45 | else: 46 | get_ip_by_hostname(hostname=resp) 47 | 48 | if __name__ == '__main__': 49 | main() --------------------------------------------------------------------------------