-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmping.py
More file actions
executable file
·34 lines (27 loc) · 836 Bytes
/
mping.py
File metadata and controls
executable file
·34 lines (27 loc) · 836 Bytes
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
#!/usr/bin/env python2
# coding = utf8
import sys
import os
n = 10
ipfile = '/home/zz/bin/DNS'
tmpfile = '/tmp/mpinglog'
def out():
f = open(tmpfile)
for line in f.readlines():
if line.strip() and not line.startswith('#'):
if line.startswith('---') \
or line.startswith('rtt') \
or line.find('packets transmitted') != -1:
print line,
if __name__ == '__main__':
print 'start ping for ' + str(n) + ' times...'
if len(sys.argv) > 1:
ipfile = sys.argv[1]
f = open(ipfile)
for line in f.readlines():
if line.strip() and not line.startswith('#'):
cmd = 'ping -c ' + str(n) + ' ' + line[:-1] \
+ ' > ' + tmpfile
# print cmd
os.system(cmd)
out()