-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest.py
More file actions
39 lines (26 loc) · 729 Bytes
/
test.py
File metadata and controls
39 lines (26 loc) · 729 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
33
34
35
36
37
38
39
# importing libraries
import subprocess
import os
# a function to ping given host
def ping(host):
# command is pong
cmd = 'ping'
# send two packets of data to the host
# this is specified by '-c 2' in the
# args list
temp = subprocess.Popen([cmd, '-c 2', host], stdout = subprocess.PIPE)
# get the output of ping
output = str(temp.communicate())
output = output.split("\n")
output = output[0].split('\\')
# variable to store the result
res = []
for line in output:
res.append(line)
# print the results
print('ping results: ')
print('\n'.join(res[len(res) - 3:len(res) - 1]))
return res
if __name__ == '__main__':
# ping google
ping('www.google.com')