Skip to content

Commit dc51077

Browse files
Improved my code
1 parent de73a7e commit dc51077

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed
Loading
Loading
Loading

APIScripts/IP_Address API/ipTracker.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22
#If writing this statement gives you an error, then this module isn't installed in your system
33
#To install, type : pip install requests
44

5-
from simple_colors import * #A module to print bold/italic/underlined texts of different colours
5+
from simple_colors import * #A module to print bold/italic/underlined texts of different colours
66
#To install, type : pip install simple-colors
7+
#PS: Different types of formatted text will not work in IDLE
78

8-
url= "http://ip-api.com/json/" #This URL is related to info about IP Address
9-
url2= "http://8xgcd1gizl6s04w7a300wyxathwtrt5l.edns.ip-api.com/json/" #This URL is related to info about DNS Server
109

11-
ip=input(cyan("Enter any IP Address (Just hit enter if you want info about your current IP Address)\n","bold"))
10+
url = "http://ip-api.com/json/" #This URL is related to info about IP Address
11+
url2 = "http://8xgcd1gizl6s04w7a300wyxathwtrt5l.edns.ip-api.com/json/" #This URL is related to info about DNS Server
12+
13+
ip = input(cyan("Enter any IP Address (Just hit enter if you want info about your current IP Address)\n","bold"))
1214
print()
1315

14-
data=requests.get(url+ip).json() #No API key required
16+
data = requests.get(url+ip).json() #No API key required
1517

16-
if ip=='':
17-
dns_data=requests.get(url2).json() #We can only find info about DNS Server of the IP Address that is currently been used
18+
if ip == '': #if user did'nt entered anything (i.e. he wants info about his/her IP Address)
19+
#We can find dns related info of the current IP Address only
20+
dns_data = requests.get(url2).json()
1821

19-
if data['status']=='fail':
20-
print(red("You entered a wrong IP Address ","bold"))
22+
if data['status'] == 'fail': # i.e. if an invalid IP Address is entered
23+
print(red("You entered an invalid IP Address ","bold"))
2124

2225
else:
2326
print(f'IP ADDRESS: {green(data["query"],"bold")} \n')
@@ -28,29 +31,29 @@
2831

2932
print(f'REGION: {green(data["regionName"],"bold")} \n')
3033

31-
o=str(data["lat"]) + " degrees"
32-
print(f'LATITUDE: {green(o,"bold")} \n')
34+
latitude = str(data["lat"]) + " degrees"
35+
print(f'LATITUDE: {green(latitude,"bold")} \n')
3336

34-
q=str(data["lon"]) + " degrees"
35-
print(f'LONGITUDE: {green(q,"bold")} \n')
37+
longitude = str(data["lon"]) + " degrees"
38+
print(f'LONGITUDE: {green(longitude,"bold")} \n')
3639

3740
print(f'TIMEZONE: {green(data["timezone"],"bold")}\n')
3841

3942
print(f'ISP: {green(data["isp"],"bold")} \n')
4043

4144
print(f'ORGANISATION: {green(data["org"],"bold")} \n')
4245

43-
if ip=='':
46+
if ip == '': #if user did'nt entered anything (i.e. he wants info about his/her IP)
4447

4548
for i in range(len(dns_data["dns"]["geo"])):
46-
if dns_data["dns"]["geo"][i]=='-':
49+
if dns_data["dns"]["geo"][i] == '-':
4750
break
4851

4952
dns_name = dns_data["dns"]["geo"][i+2:]
5053

5154
dns_country = dns_data["dns"]["geo"][:i-1]
5255

53-
j=dns_name +" (" + dns_country + ")"
56+
j = dns_name +" (" + dns_country + ")"
5457
print(f'YOUR DNS SERVER: {green(j,"bold")} \n')
5558

5659
print(f'IP ADDRESS OF YOUR DNS SERVER: {green(dns_data["dns"]["ip"],"bold")}')

0 commit comments

Comments
 (0)