-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMaplePing.py
More file actions
136 lines (119 loc) · 3.73 KB
/
MaplePing.py
File metadata and controls
136 lines (119 loc) · 3.73 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import os
from tcp_latency import measure_latency
import numpy as np
channel_rtt = np.array(range(40), np.float)
#count the ip which has no feedback
withoutfb_cnt = 0
def get_ip(ch):
if ch > 30:
ip = "202.80.104." + str(((ch - 30) // 2) + 154) # only happens in world 0
else:
ip = "202.80.104." + str((ch // 2) + init)
return ip
def get_port(ch):
if ch % 2 == 0:
return 8585
else:
return 8686
def ping_job(channel):
result = measure_latency(host = get_ip(channel), port = get_port(channel), timeout=2.5)
#print(result[0])
if result[0] is None:
result[0] = 999999
global withoutfb_cnt
withoutfb_cnt = withoutfb_cnt + 1
channel_rtt[channel] = round(result[0],3)
#print("CH.", channel + 1,"= ", channel_rtt[channel], "ms")
if __name__ == '__main__':
print("******************")
print("伺服器 編號")
print()
print("艾麗亞: 0")
print("普力特: 1")
print("琉德: 2")
print("優依娜: 3")
print("愛麗西亞: 4")
print("殺人鯨: 6")
print("Reboot: 45")
print()
print("******************")
print("上面是每個伺服器對應的編號,請輸入編號來查看本機與伺服器之間延遲狀況:")
w = {0, 1, 2, 3, 4, 6, 45}
while True:
print()
print("上面是每個伺服器對應的編號,請輸入編號來查看本機與伺服器之間延遲狀況:")
print("(Please enter a world number based on the list above.)")
channel_rtt = np.array(range(40), np.float)
withoutfb_cnt = 0
while True:
world = input()
try:
world = int(world)
if world in w:
print("Please wait for a while...")
break
else:
print("Please re-enter a legal world number:")
continue
except:
print("Please re-enter a legal world number:")
continue
if world == 6: # there's no world 5
world = world - 1
if world == 45: #World Reboot is very special...
init = 164
dungeon_ip = "202.80.104.39"
mall_ip = "202.80.104.47"
else:
init = 64 + world * 15
dungeon_ip = "202.80.104." + str(32 + world)
mall_ip = "202.80.104." + str(40 + world)
auction_ip = "202.80.104." + str(40 + world)
if world == 0: #World 0 has 40 channels
try:
for i in range(40):
ping_job(i)
for i in range(40):
print("CH.", i + 1,"= ", channel_rtt[i], "ms")
except:
pass
else:
try:
for i in range(30):
ping_job(i)
for i in range(30):
print("CH.", i + 1,"= ", channel_rtt[i], "ms")
except:
pass
channel_rtt = channel_rtt.tolist()
if world != 0:
max_value = max(channel_rtt[0:30])
min_value = min(channel_rtt[0:30])
else:
max_value = max(channel_rtt)
min_value = min(channel_rtt)
if withoutfb_cnt > 15:
print("伺服器可能在維修中或是掛了")
else:
print()
print("最大延遲頻道:", channel_rtt.index(max_value)+1, ",RTT = ", max_value, "ms")
print("最小延遲頻道:", channel_rtt.index(min_value)+1, ",RTT = ", min_value, "ms")
print("建議去 CH.",channel_rtt.index(min_value)+1)
print()
result_dungeon = measure_latency(dungeon_ip, 8686)[0]
result_mall = measure_latency(mall_ip, 8686)[0]
if result_dungeon is None:
print("副本: 9999999.0 ms")
else:
print("副本: ", round(result_dungeon, 3), "ms")
if result_mall is None:
print("商城: 9999999.0 ms")
else:
print("商城: ", round(result_mall, 3), "ms")
if world != 45: #World Reboot has no Auction system
result_auction = measure_latency(auction_ip, 8686)[0]
if result_auction is None:
print("拍賣: 9999999.0 ms")
else:
print("拍賣: ", round(measure_latency(auction_ip, 8787)[0],3), "ms")
os.system("pause")