-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyip.py
More file actions
76 lines (57 loc) · 1.49 KB
/
pyip.py
File metadata and controls
76 lines (57 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import sys
import re
import geocoder
import ipapi
import folium
import pyfiglet as figlet
res= figlet.figlet_format("PYIP Scanner")
print(res)
if(len(sys.argv)==2):
IP=sys.argv[1]
else:
IP=0
def main():
global IP
if(is_valid_arg(IP)==True):
if(is_valid_ip(IP)==True):
output()
map()
def is_valid_arg(IP):
if(len(sys.argv)==2):
return(True)
else:
sys.exit("Invalid Number of arguments")
def is_valid_ip(IP):
regex = r"^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$"
if(re.search(regex,IP) and ip_location(IP)!=[]):
return(True)
else:
sys.exit("Invalid ip....exiting!")
def ip_location(IP):
coords=geocoder.ip(IP)
return(coords.latlng)
def ip_details(IP):
info=ipapi.location(ip=IP)
return(info)
def output():
global IP
lat,lang=ip_location(IP)
print("LAT: ",lat)
print("LONG: ",lang)
info=ip_details(IP)
print("Network :",info["network"])
print("Version :",info["version"])
print("City :",info["city"])
print("Region :",info["region"])
print("Country :",info["country_name"])
print("Organization :",info["org"])
print("Postal :",info["postal"])
print("Timezone :",info["timezone"])
def map():
global IP
loc=ip_location(IP)
map=folium.Map(location=loc,zoom_start=15)
folium.Marker(location=loc).add_to(map)
map.save("map.html")
if __name__=="__main__":
main()