mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2025-05-17 22:56:42 +00:00
Updated
This commit is contained in:
parent
163c7946b8
commit
1a1b5d506a
@ -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`
|
@ -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')
|
Loading…
x
Reference in New Issue
Block a user