This commit is contained in:
Beh185 2023-09-04 11:40:48 +03:30
parent 163c7946b8
commit 1a1b5d506a
3 changed files with 62 additions and 21 deletions

View File

@ -1,3 +1,19 @@
# IP Address # IP Address
This scripts will print IP address of machine and info realted to the IP address . This scripts will give you some useful information about your ip address. For instance:
- IP address 🧭
- Continent 🌍
- Country 🗾
- City 🏘️
- Area 🏠
- Postal code 📮
- Isp 🏢
- Using Mobile 📱
- Using Proxy 🌐
## Installation
After downloading the script you can simply install requirement by:\
> `pip install -r requirements.txt`
and then
> `python main.py`

View File

@ -1,27 +1,52 @@
import requests # Import Part
from os import system
try:
from requests import get, Response, ReadTimeout
except ImportError:
system('pip install -r requirements.txt')
exit('Please run the program again')
# Api
ip_provider = r"https://api.techniknews.net/ipgeo/"
print('Getting ip info. It\'s may take some time ...')
ip_provider = "http://ipaddr.in/json"
user_agent = {
'User-agent': 'curl/7.82.0'
}
try : try :
web_request = requests.get(ip_provider, headers=user_agent , timeout=10) response: Response = get(ip_provider, timeout=20)
response = web_request.json() if response.status_code != 200:
exit(f"[{response.status_code} Error]")
ip = response["ip"] # Getting info from json file
city = response["city"] JsonResponse: dict = response.json()
area = response["region_name"] if JsonResponse['status'] == 'success':
zip_code = response["zip_code"] ip: str = JsonResponse["ip"]
country = response["country"] city: str = JsonResponse["city"]
area: str = JsonResponse["regionName"]
zip_code: str = JsonResponse["zip"]
country: str = JsonResponse["country"]
continent: str = JsonResponse['continent']
isp: str = JsonResponse['isp']
IsMobile: bool = JsonResponse['mobile']
UseProxy: bool = JsonResponse['proxy']
else:
exit('The operation was unsuccessful. Try again')
print( print(
f""" f"""
IP address : {ip} IP address : {ip}
Continent : {continent}
Country : {country}
City : {city} City : {city}
Area : {area} Area : {area}
Postal code : {zip_code} Postal code : {zip_code}
Country : {country} Isp : {isp}
Using Mobile : {IsMobile}
Using Proxy : {UseProxy}
""" """
) )
except : except ConnectionError:
print("Error !! Check your internt connection") exit("Error !! Check your internet connection")
except KeyboardInterrupt:
exit('The operation canceled by user')
except ReadTimeout:
exit('Timeout has reached')