summaryrefslogtreecommitdiffstats
path: root/notFinishedCode/tricode/PingClass.py
diff options
context:
space:
mode:
authorRefik Hadzialic2011-11-09 18:42:20 +0100
committerRefik Hadzialic2011-11-09 18:42:20 +0100
commitc9c5ce360606570ae9eb01cae68234ac962b7989 (patch)
treeff5d5f9e237223d28a42fc7b8a0cf07ebdea4249 /notFinishedCode/tricode/PingClass.py
parentdelete unnecessary files (diff)
downloadgsm-selftest-c9c5ce360606570ae9eb01cae68234ac962b7989.tar.gz
gsm-selftest-c9c5ce360606570ae9eb01cae68234ac962b7989.tar.xz
gsm-selftest-c9c5ce360606570ae9eb01cae68234ac962b7989.zip
Tiny changes
Diffstat (limited to 'notFinishedCode/tricode/PingClass.py')
-rwxr-xr-xnotFinishedCode/tricode/PingClass.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/notFinishedCode/tricode/PingClass.py b/notFinishedCode/tricode/PingClass.py
new file mode 100755
index 0000000..e13b32b
--- /dev/null
+++ b/notFinishedCode/tricode/PingClass.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