From 65c9b8b6b1a46b79b72e266e0036d4992ce62589 Mon Sep 17 00:00:00 2001 From: Triatmoko Date: Mon, 1 Aug 2011 14:41:47 +0200 Subject: add new file for agustus. this test include truetable to indicate which part is broken and also have test adjusment which onl test importan part in the network. --- For Weekly Test/19-08-2011/PingClass.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 For Weekly Test/19-08-2011/PingClass.py (limited to 'For Weekly Test/19-08-2011/PingClass.py') diff --git a/For Weekly Test/19-08-2011/PingClass.py b/For Weekly Test/19-08-2011/PingClass.py new file mode 100644 index 0000000..e13b32b --- /dev/null +++ b/For Weekly Test/19-08-2011/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 -- cgit v1.2.3-55-g7522