1
1
#!/usr/bin/python
2
2
# -*- coding: UTF-8 -*-
3
+ < << << << HEAD
4
+ == == == =
5
+ import urllib
6
+ import urllib2
7
+ > >> >> >> dev
3
8
4
9
def change_to_list (filename ):
5
10
content = open (filename ,"r" ).read ().strip ()
@@ -17,16 +22,47 @@ def traceroute_to_dict(filename):
17
22
line = content [i ]
18
23
if line [1 ].isdigit ():
19
24
if line [4 ] != "*" :
20
- latency = line .strip ().split (" " )[2 ]
25
+ < << << << HEAD
26
+ ip = line .strip ().split (" " )[1 ]
21
27
asn = line .strip ().split (" " )[3 ]
28
+ iptest = ip .strip ().split (" " )[0 ]
29
+ url = "http://ip-api.com/csv/" + iptest
30
+ req = urllib2 .Request (url )
31
+ res_data = urllib2 .urlopen (req )
32
+ res = res_data .read ()
33
+ if res .strip ().split ("," )[0 ] == "success" :
34
+ isp = res .strip ().split ("," )[11 ]
35
+ asn = res .strip ().split ("," )[12 ]
36
+ else :
37
+ isp = "*"
38
+ latency = line .strip ().split (" " )[2 ]
22
39
route = line .strip ().split (" " )[4 ]
40
+ == == == =
23
41
ip = line .strip ().split (" " )[1 ]
42
+ asn = line .strip ().split (" " )[3 ]
43
+ iptest = ip .strip ().split (" " )[0 ]
44
+ url = "http://ip-api.com/csv/" + iptest
45
+ req = urllib2 .Request (url )
46
+ res_data = urllib2 .urlopen (req )
47
+ res = res_data .read ()
48
+ if res .strip ().split ("," )[0 ] == "success" :
49
+ isp = res .strip ().split ("," )[11 ]
50
+ asn = res .strip ().split ("," )[12 ]
51
+ else :
52
+ isp = "*"
53
+ latency = line .strip ().split (" " )[2 ]
54
+ route = line .strip ().split (" " )[4 ]
55
+ >> >> >> > dev
24
56
step = line [0 :2 ]
25
57
else :
26
58
latency = "*"
27
59
asn = "*"
28
60
route = "*"
29
61
ip = "*"
62
+ < << << << HEAD
63
+ == == == =
64
+ isp = "*"
65
+ >> >> >> > dev
30
66
step = line [0 :2 ]
31
67
32
68
d [int (step )]= dict ()
@@ -36,7 +72,11 @@ def traceroute_to_dict(filename):
36
72
d [int (step )]["latency" ]= latency
37
73
d [int (step )]["asn" ]= asn
38
74
d [int (step )]["route" ]= route
75
+ < << << << HEAD
39
76
77
+ == == == =
78
+ d [int (step )]["isp" ]= isp
79
+ >> >> >> > dev
40
80
41
81
return dict (d )
42
82
@@ -52,9 +92,16 @@ def traceroute_to_table(filename):
52
92
<td>{}</td>
53
93
<td>{}</td>
54
94
<td>{}</td>
95
+ <<<<<<< HEAD
55
96
</tr>
56
97
"""
57
98
string = string + template .format (i ,x ["ip" ],x ["route" ],x ["asn" ],x ["latency" ]) + "\n "
99
+ == == == =
100
+ < td > {}< / td >
101
+ < / tr >
102
+ """
103
+ string = string + template.format(i,x["ip"],x["route"],x["isp"],x["asn"],x["latency"]) + "\n "
104
+ >>>>>>> dev
58
105
59
106
writefile = open(filename + "_table","w")
60
107
writefile.write(string)
@@ -75,6 +122,10 @@ def dict_to_table(d,tab):
75
122
< tr > < th > 跳数 < / th >
76
123
< th > IP < / th >
77
124
< th > 路由 < / th >
125
+ < << << << HEAD
126
+ == == == =
127
+ < th > ISP < / th >
128
+ >> >> >> > dev
78
129
< th > AS Number < / th >
79
130
< th > 延迟 < / th >
80
131
< / tr > < / thead >
@@ -90,9 +141,16 @@ def dict_to_table(d,tab):
90
141
< td > {2 }< / td >
91
142
< td > {3 }< / td >
92
143
< td > {4 }< / td >
144
+ < << << << HEAD
93
145
< / tr >
94
146
95
147
""".format(step,d[step]["ip"],d[step]["route"],d[step]["asn"],d[step]["latency"])
148
+ =======
149
+ <td>{5}</td>
150
+ </tr>
151
+
152
+ """ .format (step ,d [step ]["ip" ],d [step ]["route" ],d [step ]["isp" ],d [step ]["asn" ],d [step ]["latency" ])
153
+ > >> >> >> dev
96
154
97
155
table_html = table_html + """
98
156
</tbody>
@@ -479,6 +537,10 @@ def dict_to_table(d,tab):
479
537
<a class="item" data-tab="fourth">广东移动</a>
480
538
<a class="item" data-tab="fifth">广东电信</a>
481
539
<a class="item" data-tab="sixth">广东联通</a>
540
+ <<<<<<< HEAD
541
+ =======
542
+ <a class="item" data-tab="seventh">所在地IP</a>
543
+ >>>>>>> dev
482
544
</div>
483
545
484
546
"""
@@ -627,6 +689,12 @@ def dict_to_table(d,tab):
627
689
traceroute_to_table ("/tmp/gdu.txt" )
628
690
gdu_html = dict_to_table (gdu ,"sixth" )
629
691
692
+ < << << << HEAD
693
+ == == == =
694
+ own = traceroute_to_dict ("/tmp/own.txt" )
695
+ traceroute_to_table ("/tmp/own.txt" )
696
+ own_html = dict_to_table (own ,"seventh" )
697
+ > >> >> >> dev
630
698
631
699
html = html .format (info [0 ],info [1 ],info [2 ],info [3 ],info [4 ],info [5 ],info [6 ],info [7 ],info [8 ],info [9 ],info [10 ],info [11 ],info [12 ],info [13 ],info [14 ], \
632
700
@@ -640,7 +708,11 @@ def dict_to_table(d,tab):
640
708
641
709
speed_cn [18 ],speed_cn [19 ],speed_cn [20 ],speed_cn [21 ],speed_cn [22 ],speed_cn [23 ])
642
710
711
+ < << << << HEAD
643
712
html = html + shm_html + sht_html + shu_html + gdm_html + gdt_html + gdu_html + footer
713
+ == == == =
714
+ html = html + shm_html + sht_html + shu_html + gdm_html + gdt_html + gdu_html + own_html + footer
715
+ > >> >> >> dev
644
716
645
717
web = open ("/root/report.html" ,"w" )
646
718
0 commit comments