mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2025-05-17 14:46:43 +00:00
Updated
This commit is contained in:
parent
163c7946b8
commit
1a1b5d506a
@ -1,3 +1,19 @@
|
||||
# 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`
|
@ -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 :
|
||||
web_request = requests.get(ip_provider, headers=user_agent , timeout=10)
|
||||
response = web_request.json()
|
||||
|
||||
ip = response["ip"]
|
||||
city = response["city"]
|
||||
area = response["region_name"]
|
||||
zip_code = response["zip_code"]
|
||||
country = response["country"]
|
||||
response: Response = get(ip_provider, timeout=20)
|
||||
if response.status_code != 200:
|
||||
exit(f"[{response.status_code} Error]")
|
||||
|
||||
# Getting info from json file
|
||||
JsonResponse: dict = response.json()
|
||||
if JsonResponse['status'] == 'success':
|
||||
ip: str = JsonResponse["ip"]
|
||||
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(
|
||||
f"""
|
||||
IP address : {ip}
|
||||
City : {city}
|
||||
Area : {area}
|
||||
Postal code : {zip_code}
|
||||
Country : {country}
|
||||
IP address : {ip}
|
||||
Continent : {continent}
|
||||
Country : {country}
|
||||
City : {city}
|
||||
Area : {area}
|
||||
Postal code : {zip_code}
|
||||
Isp : {isp}
|
||||
Using Mobile : {IsMobile}
|
||||
Using Proxy : {UseProxy}
|
||||
"""
|
||||
)
|
||||
except :
|
||||
print("Error !! Check your internt connection")
|
||||
except ConnectionError:
|
||||
exit("Error !! Check your internet connection")
|
||||
except KeyboardInterrupt:
|
||||
exit('The operation canceled by user')
|
||||
except ReadTimeout:
|
||||
exit('Timeout has reached')
|
Loading…
x
Reference in New Issue
Block a user