forked from natrix-fork/traceme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracemap.py
executable file
·47 lines (38 loc) · 1.22 KB
/
tracemap.py
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
#!/usr/bin/python2.7
import requests
import ast
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
file=open("/root/github/traceme/ip.txt","r")
ip=[]
for i in file.readlines():
ip.append(i.strip())
#print ip
city=[]
latitude=[]
longitude=[]
for i in range(len(ip)):
response=requests.get("http://ip-api.com/json/"+ip[i])
if "fail" not in response.content:
response_dict=ast.literal_eval(response.content)
city.append(response_dict['city'])
latitude.append(response_dict['lat'])
longitude.append(response_dict['lon'])
#print response.content
print city,"\n",latitude,"\n",longitude
map = Basemap(projection='cyl')
plt.title("WorldMap")
map.drawcoastlines()
map.drawmapboundary(fill_color="#7777ff")
map.fillcontinents(color="#ddaa66",lake_color="#7777ff")
for i in range(len(city)):
x,y = map(longitude[i],latitude[i])
map.plot(x,y,'g^',markersize=10)
plt.text(x,y,city[i],fontsize=6,fontweight='bold',ha='left',va='bottom',color='#8B008B', bbox=dict(facecolor='b', alpha=.1))
x,y = map(longitude,latitude)
map.plot(x,y,color='r',linewidth=2,label="DataFlow")
plt.legend(loc=4)
x,y=map(-170,-82)
plt.text(x,y,city,fontsize=6,fontweight='bold')
plt.savefig('map.png',dpi=1000,bbox_inches='tight')
plt.show()