|
2 | 2 | #If writing this statement gives you an error, then this module isn't installed in your system
|
3 | 3 | #To install, type : pip install requests
|
4 | 4 |
|
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 |
6 | 6 | #To install, type : pip install simple-colors
|
| 7 | + #PS: Different types of formatted text will not work in IDLE |
7 | 8 |
|
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 |
10 | 9 |
|
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")) |
12 | 14 | print()
|
13 | 15 |
|
14 |
| -data=requests.get(url+ip).json() #No API key required |
| 16 | +data = requests.get(url+ip).json() #No API key required |
15 | 17 |
|
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() |
18 | 21 |
|
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")) |
21 | 24 |
|
22 | 25 | else:
|
23 | 26 | print(f'IP ADDRESS: {green(data["query"],"bold")} \n')
|
|
28 | 31 |
|
29 | 32 | print(f'REGION: {green(data["regionName"],"bold")} \n')
|
30 | 33 |
|
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') |
33 | 36 |
|
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') |
36 | 39 |
|
37 | 40 | print(f'TIMEZONE: {green(data["timezone"],"bold")}\n')
|
38 | 41 |
|
39 | 42 | print(f'ISP: {green(data["isp"],"bold")} \n')
|
40 | 43 |
|
41 | 44 | print(f'ORGANISATION: {green(data["org"],"bold")} \n')
|
42 | 45 |
|
43 |
| - if ip=='': |
| 46 | + if ip == '': #if user did'nt entered anything (i.e. he wants info about his/her IP) |
44 | 47 |
|
45 | 48 | for i in range(len(dns_data["dns"]["geo"])):
|
46 |
| - if dns_data["dns"]["geo"][i]=='-': |
| 49 | + if dns_data["dns"]["geo"][i] == '-': |
47 | 50 | break
|
48 | 51 |
|
49 | 52 | dns_name = dns_data["dns"]["geo"][i+2:]
|
50 | 53 |
|
51 | 54 | dns_country = dns_data["dns"]["geo"][:i-1]
|
52 | 55 |
|
53 |
| - j=dns_name +" (" + dns_country + ")" |
| 56 | + j = dns_name +" (" + dns_country + ")" |
54 | 57 | print(f'YOUR DNS SERVER: {green(j,"bold")} \n')
|
55 | 58 |
|
56 | 59 | print(f'IP ADDRESS OF YOUR DNS SERVER: {green(dns_data["dns"]["ip"],"bold")}')
|
|
0 commit comments