FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python/check_ping.py at master · ttua/python · GitHub
ttua
/
python
Public
forked from
rocfy/python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python
/
check_ping.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (36 loc) · 1.06 KB
Breadcrumbs
python
/
check_ping.py
Copy path
File metadata and controls
39 lines (36 loc) · 1.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/python
#coding:utf-8
import
multiprocessing
import
re
import
sys
,
os
import
commands
import
datetime
def
pinger
(
ip
):
cmd
=
'ping -c 2 %s'
%
(
ip
.
strip
())
ret
=
commands
.
getoutput
(
cmd
)
loss_re
=
re
.
compile
(
r"received, (.*) packet loss"
)
packet_loss
=
loss_re
.
findall
(
ret
)[
0
]
rtt_re
=
re
.
compile
(
r"rtt min/avg/max/mdev = (.*) "
)
rtts
=
rtt_re
.
findall
(
ret
)
#rtt.split(["/"])
rtt
=
rtts
[
0
].
split
(
'/'
)
rtt_min
=
rtt
[
0
]
rtt_avg
=
rtt
[
1
]
rtt_max
=
rtt
[
2
]
print
"%s
\t
\t
%s
\t
\t
%s
\t
\t
%s
\t
\t
%s"
%
(
ip
,
packet_loss
,
rtt_min
,
rtt_max
,
rtt_avg
)
if
__name__
==
"__main__"
:
if
not
os
.
path
.
exists
(
"hosts.txt"
) :
print
"
\033
[31mhosts.txt文件不存在,请重试
\033
[0m"
sys
.
exit
(
1
)
now
=
datetime
.
datetime
.
now
()
file
=
open
(
'hosts.txt'
,
'r'
)
pool
=
multiprocessing
.
Pool
(
processes
=
4
)
result
=
[]
print
"########%s###########"
%
now
print
"IPADDRSS
\t
\t
\t
LOSS
\t
\t
MIN
\t
\t
MAX
\t
\t
AVG"
for
i
in
file
.
readlines
():
if
len
(
i
)
==
1
or
i
.
startswith
(
"#"
):
continue
result
.
append
(
pool
.
apply_async
(
pinger
,(
i
.
strip
(),)))
pool
.
close
()
pool
.
join
()
Back
|
FazBrowse Home
|
New Git URL