Skip to content

Commit 73b8545

Browse files
committed
添加回程至所在地路由,完善ISP名称和AS号
1 parent 4576d53 commit 73b8545

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

Generate.py

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/python
22
# -*- coding: UTF-8 -*-
3+
import urllib
4+
import urllib2
35

46
def change_to_list(filename):
57
content = open(filename,"r").read().strip()
@@ -17,16 +19,27 @@ def traceroute_to_dict(filename):
1719
line = content[i]
1820
if line[1].isdigit():
1921
if line[4] != "*" :
20-
latency=line.strip().split(" ")[2]
22+
ip = line.strip().split(" ")[1]
2123
asn = line.strip().split(" ")[3]
24+
iptest = ip.strip().split(" ")[0]
25+
url = "http://ip-api.com/csv/" + iptest
26+
req = urllib2.Request(url)
27+
res_data = urllib2.urlopen(req)
28+
res = res_data.read()
29+
if res.strip().split(",")[0] == "success" :
30+
isp=res.strip().split(",")[11]
31+
asn=res.strip().split(",")[12]
32+
else:
33+
isp= "*"
34+
latency=line.strip().split(" ")[2]
2235
route = line.strip().split(" ")[4]
23-
ip = line.strip().split(" ")[1]
2436
step = line[0:2]
2537
else:
2638
latency="*"
2739
asn = "*"
2840
route = "*"
2941
ip = "*"
42+
isp= "*"
3043
step = line[0:2]
3144

3245
d[int(step)]=dict()
@@ -36,7 +49,7 @@ def traceroute_to_dict(filename):
3649
d[int(step)]["latency"]=latency
3750
d[int(step)]["asn"]=asn
3851
d[int(step)]["route"]=route
39-
52+
d[int(step)]["isp"]=isp
4053

4154
return dict(d)
4255

@@ -52,9 +65,10 @@ def traceroute_to_table(filename):
5265
<td>{}</td>
5366
<td>{}</td>
5467
<td>{}</td>
68+
<td>{}</td>
5569
</tr>
5670
"""
57-
string = string + template.format(i,x["ip"],x["route"],x["asn"],x["latency"]) + "\n"
71+
string = string + template.format(i,x["ip"],x["route"],x["isp"],x["asn"],x["latency"]) + "\n"
5872

5973
writefile = open(filename + "_table","w")
6074
writefile.write(string)
@@ -75,6 +89,7 @@ def dict_to_table(d,tab):
7589
<tr><th>跳数</th>
7690
<th>IP</th>
7791
<th>路由</th>
92+
<th>ISP</th>
7893
<th>AS Number</th>
7994
<th>延迟</th>
8095
</tr></thead>
@@ -90,9 +105,10 @@ def dict_to_table(d,tab):
90105
<td>{2}</td>
91106
<td>{3}</td>
92107
<td>{4}</td>
108+
<td>{5}</td>
93109
</tr>
94110
95-
""".format(step,d[step]["ip"],d[step]["route"],d[step]["asn"],d[step]["latency"])
111+
""".format(step,d[step]["ip"],d[step]["route"],d[step]["isp"],d[step]["asn"],d[step]["latency"])
96112

97113
table_html = table_html + """
98114
</tbody>
@@ -479,6 +495,7 @@ def dict_to_table(d,tab):
479495
<a class="item" data-tab="fourth">广东移动</a>
480496
<a class="item" data-tab="fifth">广东电信</a>
481497
<a class="item" data-tab="sixth">广东联通</a>
498+
<a class="item" data-tab="seventh">所在地IP</a>
482499
</div>
483500
484501
"""
@@ -627,6 +644,9 @@ def dict_to_table(d,tab):
627644
traceroute_to_table("/tmp/gdu.txt")
628645
gdu_html = dict_to_table(gdu,"sixth")
629646

647+
own = traceroute_to_dict("/tmp/own.txt")
648+
traceroute_to_table("/tmp/own.txt")
649+
own_html = dict_to_table(own,"seventh")
630650

631651
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], \
632652

@@ -640,7 +660,7 @@ def dict_to_table(d,tab):
640660

641661
speed_cn[18],speed_cn[19],speed_cn[20],speed_cn[21],speed_cn[22],speed_cn[23])
642662

643-
html = html + shm_html + sht_html + shu_html + gdm_html + gdt_html + gdu_html + footer
663+
html = html + shm_html + sht_html + shu_html + gdm_html + gdt_html + gdu_html + own_html + footer
644664

645665
web = open("/root/report.html","w")
646666

ZBench-CN.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ NetPiSM=$( sed -n "24p" /tmp/speed_cn.txt )
389389
NetUPCM=$( sed -n "25p" /tmp/speed_cn.txt )
390390
NetDWCM=$( sed -n "26p" /tmp/speed_cn.txt )
391391
NetPiCM=$( sed -n "27p" /tmp/speed_cn.txt )
392-
wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/Generate.py >> /dev/null 2>&1
392+
wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/dev/Generate.py >> /dev/null 2>&1
393393
python Generate.py && rm -rf Generate.py && cp /root/report.html /tmp/report/index.html
394394
TSM=$( cat /tmp/shm.txt_table )
395395
TST=$( cat /tmp/sht.txt_table )

0 commit comments

Comments
 (0)