11#!/usr/bin/python
22# -*- coding: UTF-8 -*-
3+ < << << << HEAD
4+ == == == =
5+ import urllib
6+ import urllib2
7+ > >> >> >> dev
38
49def change_to_list (filename ):
510 content = open (filename ,"r" ).read ().strip ()
@@ -17,16 +22,47 @@ def traceroute_to_dict(filename):
1722 line = content [i ]
1823 if line [1 ].isdigit ():
1924 if line [4 ] != "*" :
20- latency = line .strip ().split (" " )[2 ]
25+ < << << << HEAD
26+ ip = line .strip ().split (" " )[1 ]
2127 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 ]
2239 route = line .strip ().split (" " )[4 ]
40+ == == == =
2341 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
2456 step = line [0 :2 ]
2557 else :
2658 latency = "*"
2759 asn = "*"
2860 route = "*"
2961 ip = "*"
62+ < << << << HEAD
63+ == == == =
64+ isp = "*"
65+ >> >> >> > dev
3066 step = line [0 :2 ]
3167
3268 d [int (step )]= dict ()
@@ -36,7 +72,11 @@ def traceroute_to_dict(filename):
3672 d [int (step )]["latency" ]= latency
3773 d [int (step )]["asn" ]= asn
3874 d [int (step )]["route" ]= route
75+ < << << << HEAD
3976
77+ == == == =
78+ d [int (step )]["isp" ]= isp
79+ >> >> >> > dev
4080
4181 return dict (d )
4282
@@ -52,9 +92,16 @@ def traceroute_to_table(filename):
5292 <td>{}</td>
5393 <td>{}</td>
5494 <td>{}</td>
95+ <<<<<<< HEAD
5596 </tr>
5697 """
5798 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
58105
59106 writefile = open(filename + "_table","w")
60107 writefile.write(string)
@@ -75,6 +122,10 @@ def dict_to_table(d,tab):
75122 < tr > < th > 跳数 < / th >
76123 < th > IP < / th >
77124 < th > 路由 < / th >
125+ < << << << HEAD
126+ == == == =
127+ < th > ISP < / th >
128+ >> >> >> > dev
78129 < th > AS Number < / th >
79130 < th > 延迟 < / th >
80131 < / tr > < / thead >
@@ -90,9 +141,16 @@ def dict_to_table(d,tab):
90141 < td > {2 }< / td >
91142 < td > {3 }< / td >
92143 < td > {4 }< / td >
144+ < << << << HEAD
93145 < / tr >
94146
95147 """.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
96154
97155 table_html = table_html + """
98156 </tbody>
@@ -479,6 +537,10 @@ def dict_to_table(d,tab):
479537 <a class="item" data-tab="fourth">广东移动</a>
480538 <a class="item" data-tab="fifth">广东电信</a>
481539 <a class="item" data-tab="sixth">广东联通</a>
540+ <<<<<<< HEAD
541+ =======
542+ <a class="item" data-tab="seventh">所在地IP</a>
543+ >>>>>>> dev
482544</div>
483545
484546"""
@@ -627,6 +689,12 @@ def dict_to_table(d,tab):
627689traceroute_to_table ("/tmp/gdu.txt" )
628690gdu_html = dict_to_table (gdu ,"sixth" )
629691
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
630698
631699html = 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 ], \
632700
@@ -640,7 +708,11 @@ def dict_to_table(d,tab):
640708
641709speed_cn [18 ],speed_cn [19 ],speed_cn [20 ],speed_cn [21 ],speed_cn [22 ],speed_cn [23 ])
642710
711+ < << << << HEAD
643712html = 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
644716
645717web = open ("/root/report.html" ,"w" )
646718
0 commit comments