Skip to content

Commit

Permalink
根据建议换成tcp ping: 443回程
Browse files Browse the repository at this point in the history
  • Loading branch information
ubuntu committed Sep 3, 2018
1 parent b1166a5 commit 8ce0080
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 39 deletions.
47 changes: 28 additions & 19 deletions clients/client-linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,47 +161,56 @@ def get_network(ip_version):
'189': 0.0,
'10086': 0.0
}
def _ping_thread(host, mark):
output = os.popen('ping -O %s &' % host)
lostCount = 0
allCount = 0
def _ping_thread(host, mark, port):
lostPacket = 0
allPacket = 0
startTime = time.time()
output.readline()

while True:
buffer = output.readline()
if len(buffer) == 0:
return
if 'ttl' not in buffer:
lostCount += 1
allCount += 1
if allCount > 100:
lostRate[mark] = float(lostCount) / allCount
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
try:
s.connect((host, port))
except:
lostPacket += 1
finally:
allPacket += 1
s.close()

if allPacket > 100:
lostRate[mark] = float(lostPacket) / allPacket

endTime = time.time()
if endTime-startTime > 3600:
lostCount = 0
allCount = 0
if endTime - startTime > 3600:
lostPacket = 0
allPacket = 0
startTime = endTime

time.sleep(1)

def get_packetLostRate():
t1 = threading.Thread(
target=_ping_thread,
kwargs={
'host': 'cu.tz.cloudcpp.com',
'mark': '10010'
'mark': '10010',
'port': 443
}
)
t2 = threading.Thread(
target=_ping_thread,
kwargs={
'host': 'ct.tz.cloudcpp.com',
'mark': '189'
'mark': '189',
'port': 443
}
)
t3 = threading.Thread(
target=_ping_thread,
kwargs={
'host': 'cm.tz.cloudcpp.com',
'mark': '10086'
'mark': '10086',
'port': 443
}
)
t1.setDaemon(True)
Expand Down
48 changes: 28 additions & 20 deletions clients/client-psutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,48 +129,56 @@ def get_network(ip_version):
'189': 0.0,
'10086': 0.0
}
def _ping_thread(host, mark):
output = os.popen('ping -O %s &' % host if 'linux' in sys.platform else 'ping %s -t &' % host)
lostCount = 0
allCount = 0
def _ping_thread(host, mark, port):
lostPacket = 0
allPacket = 0
startTime = time.time()
output.readline()
output.readline()

while True:
buffer = output.readline()
if len(buffer) == 0:
return
if 'TTL' not in buffer.upper():
lostCount += 1
allCount += 1
if allCount > 100:
lostRate[mark] = float(lostCount) / allCount
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
try:
s.connect((host, port))
except:
lostPacket += 1
finally:
allPacket += 1
s.close()

if allPacket > 100:
lostRate[mark] = float(lostPacket) / allPacket

endTime = time.time()
if endTime-startTime > 3600:
lostCount = 0
allCount = 0
if endTime - startTime > 3600:
lostPacket = 0
allPacket = 0
startTime = endTime

time.sleep(1)

def get_packetLostRate():
t1 = threading.Thread(
target=_ping_thread,
kwargs={
'host': 'cu.tz.cloudcpp.com',
'mark': '10010'
'mark': '10010',
'port': 443
}
)
t2 = threading.Thread(
target=_ping_thread,
kwargs={
'host': 'ct.tz.cloudcpp.com',
'mark': '189'
'mark': '189',
'port': 443
}
)
t3 = threading.Thread(
target=_ping_thread,
kwargs={
'host': 'cm.tz.cloudcpp.com',
'mark': '10086'
'mark': '10086',
'port': 443
}
)
t1.setDaemon(True)
Expand Down

0 comments on commit 8ce0080

Please sign in to comment.