根据建议换成tcp ping: 443回程

This commit is contained in:
ubuntu 2018-09-03 12:18:08 +08:00
parent b1166a540c
commit 8ce00805c5
2 changed files with 56 additions and 39 deletions

@ -161,47 +161,56 @@ lostRate = {
'189': 0.0, '189': 0.0,
'10086': 0.0 '10086': 0.0
} }
def _ping_thread(host, mark): def _ping_thread(host, mark, port):
output = os.popen('ping -O %s &' % host) lostPacket = 0
lostCount = 0 allPacket = 0
allCount = 0
startTime = time.time() startTime = time.time()
output.readline()
while True: while True:
buffer = output.readline() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if len(buffer) == 0: s.settimeout(1)
return try:
if 'ttl' not in buffer: s.connect((host, port))
lostCount += 1 except:
allCount += 1 lostPacket += 1
if allCount > 100: finally:
lostRate[mark] = float(lostCount) / allCount allPacket += 1
s.close()
if allPacket > 100:
lostRate[mark] = float(lostPacket) / allPacket
endTime = time.time() endTime = time.time()
if endTime-startTime > 3600: if endTime - startTime > 3600:
lostCount = 0 lostPacket = 0
allCount = 0 allPacket = 0
startTime = endTime startTime = endTime
time.sleep(1)
def get_packetLostRate(): def get_packetLostRate():
t1 = threading.Thread( t1 = threading.Thread(
target=_ping_thread, target=_ping_thread,
kwargs={ kwargs={
'host': 'cu.tz.cloudcpp.com', 'host': 'cu.tz.cloudcpp.com',
'mark': '10010' 'mark': '10010',
'port': 443
} }
) )
t2 = threading.Thread( t2 = threading.Thread(
target=_ping_thread, target=_ping_thread,
kwargs={ kwargs={
'host': 'ct.tz.cloudcpp.com', 'host': 'ct.tz.cloudcpp.com',
'mark': '189' 'mark': '189',
'port': 443
} }
) )
t3 = threading.Thread( t3 = threading.Thread(
target=_ping_thread, target=_ping_thread,
kwargs={ kwargs={
'host': 'cm.tz.cloudcpp.com', 'host': 'cm.tz.cloudcpp.com',
'mark': '10086' 'mark': '10086',
'port': 443
} }
) )
t1.setDaemon(True) t1.setDaemon(True)

@ -129,48 +129,56 @@ lostRate = {
'189': 0.0, '189': 0.0,
'10086': 0.0 '10086': 0.0
} }
def _ping_thread(host, mark): def _ping_thread(host, mark, port):
output = os.popen('ping -O %s &' % host if 'linux' in sys.platform else 'ping %s -t &' % host) lostPacket = 0
lostCount = 0 allPacket = 0
allCount = 0
startTime = time.time() startTime = time.time()
output.readline()
output.readline()
while True: while True:
buffer = output.readline() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if len(buffer) == 0: s.settimeout(1)
return try:
if 'TTL' not in buffer.upper(): s.connect((host, port))
lostCount += 1 except:
allCount += 1 lostPacket += 1
if allCount > 100: finally:
lostRate[mark] = float(lostCount) / allCount allPacket += 1
s.close()
if allPacket > 100:
lostRate[mark] = float(lostPacket) / allPacket
endTime = time.time() endTime = time.time()
if endTime-startTime > 3600: if endTime - startTime > 3600:
lostCount = 0 lostPacket = 0
allCount = 0 allPacket = 0
startTime = endTime startTime = endTime
time.sleep(1)
def get_packetLostRate(): def get_packetLostRate():
t1 = threading.Thread( t1 = threading.Thread(
target=_ping_thread, target=_ping_thread,
kwargs={ kwargs={
'host': 'cu.tz.cloudcpp.com', 'host': 'cu.tz.cloudcpp.com',
'mark': '10010' 'mark': '10010',
'port': 443
} }
) )
t2 = threading.Thread( t2 = threading.Thread(
target=_ping_thread, target=_ping_thread,
kwargs={ kwargs={
'host': 'ct.tz.cloudcpp.com', 'host': 'ct.tz.cloudcpp.com',
'mark': '189' 'mark': '189',
'port': 443
} }
) )
t3 = threading.Thread( t3 = threading.Thread(
target=_ping_thread, target=_ping_thread,
kwargs={ kwargs={
'host': 'cm.tz.cloudcpp.com', 'host': 'cm.tz.cloudcpp.com',
'mark': '10086' 'mark': '10086',
'port': 443
} }
) )
t1.setDaemon(True) t1.setDaemon(True)