summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/30-07-2011/classPing.py
diff options
context:
space:
mode:
authortt412011-07-23 02:58:02 +0200
committertt412011-07-23 02:58:02 +0200
commit7dad14ada675d92ac7bb94f7ea809d96374c1741 (patch)
tree9576b52798cace1dccbd7b999633e4a9b7fa94e2 /For Weekly Test/30-07-2011/classPing.py
parentadd new file. (diff)
downloadgsm-selftest-7dad14ada675d92ac7bb94f7ea809d96374c1741.tar.gz
gsm-selftest-7dad14ada675d92ac7bb94f7ea809d96374c1741.tar.xz
gsm-selftest-7dad14ada675d92ac7bb94f7ea809d96374c1741.zip
managing files.
Diffstat (limited to 'For Weekly Test/30-07-2011/classPing.py')
-rw-r--r--For Weekly Test/30-07-2011/classPing.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/For Weekly Test/30-07-2011/classPing.py b/For Weekly Test/30-07-2011/classPing.py
new file mode 100644
index 0000000..e13b32b
--- /dev/null
+++ b/For Weekly Test/30-07-2011/classPing.py
@@ -0,0 +1,28 @@
+import subprocess
+import string
+
+class Ping:
+
+ def __init__(self, pingAddress):
+ self.pingAddress = pingAddress
+
+ def ping(self,numberTries):
+ tried = 1
+ while numberTries >= tried:
+ tried += 1
+ #the parameter c 1 means only one ping to be sent, parameter W 3 means how many seconds the time out should be, 3 seconds
+ ping_cmd = subprocess.Popen(['ping', self.pingAddress, '-c', '1', '-W', '2'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
+
+ pingAlive = int(string.find(ping_cmd, '1 received'))
+ unknownHost = int(string.find(ping_cmd, 'unknown host'))
+
+
+ if pingAlive != -1:
+ break
+
+ if unknownHost != -1:
+ return 2 #unknown host
+ if pingAlive != -1:
+ return 1 #ping works fine
+ else:
+ return 0 #no ping response