forked from Pililink/dns_Speed_test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Windows.py
51 lines (48 loc) · 1.75 KB
/
Windows.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
48
49
50
51
def run(dns_list,html_list):
# !/usr/bin/python3
# -*- coding: UTF-8 -*-
import os
import re
os.system('chcp 65001')
os.system('ipconfig/flushdns')
ms_list = {}
htmllen = len(html_list)
num=0
try:
for x in dns_list:
if x == '\n' or x == '':
continue
num = 0
if x[0] != '#':
print("-----------------------------------------")
for y in html_list:
if y == '\n' or y == '':
continue
a = 'dig\\dig.exe @'+ x + " " + y
print(format(x + ' ' + y, '<30'), '响应时间:', end='')
i = 0
ms = 0
while i < 10:
zz = os.popen(a)
z = zz.readlines()[-5]
m = re.search('[1-9]\d*', z)
ms = ms + int(m.group())
i = i + 1
ms = round(ms / 10, 2)
num = num + ms
print(ms)
ms_list[x] = str(round(num / htmllen, 2))
except NoneType as e:
print('except:', e)
print('请重新运行')
ms = 999999.0
# print(x," ms = ",num/htmllen)
print("===========================================================")
for key in ms_list:
print(format(key, '<20'), end="")
print('平均响应时间:' + ms_list[key])
if float(ms_list[key]) < ms:
ms = float(ms_list[key])
print("===========================================================")
min = list(ms_list.keys())[list(ms_list.values()).index(str(ms))]
print('最优:', min, ' 平均响应时间:', round(ms, 2))