def testReusableInstanceQuietly(self): hostname = 'www.cs.helsinki.fi' count = 3 p = Pinger(hostname, 100, 256) #, own_id='python-ping') r1 = p.run(count-1, 1000, verbose=False) r2 = p.run(1, 1000, verbose=False) print_exit(hostname, merge(r1,r2))
def load_hosts(): #creates a dictionary of hosts file_obj = open(filename, 'r') temp = [] hosts = {} count = 0 garbage = True second = False while (garbage): line = file_obj.readline() if (line[0] == ';' and second == False): #at the first ';' so ignore and set second flag second = True elif (line[0] == ';'): #we are at the ';' before where we want to start reading in garbage = False line = file_obj.readline() while (line[0] != ';'): line = line.split() #split tabs print line hostname = line[0] print "hostname: " + hostname ip = line[2] print "ip: " + ip comment = " " comment = comment.join(line[4:]) print "comment: " + comment fqdn = hostname + ".kittenz.pdx.edu" pinger = Pinger(target_host=ip) avg = pinger.ping() ping = "%0.4fms" % avg info = { "hostname": hostname, "ip": ip, "owner": comment, "fqdn": fqdn, "ping": ping } hosts[hostname] = info line = file_obj.readline() print "Hosts have been read in from " + filename + "." print hosts file_obj.close() return hosts
def ping(self): if self.version == 6: res = Pinger6().ping6([self.ip]).results else: res = Pinger().ping([self.ip]).results if res == {}: return "unreachable" else: return "reachable"
def test_PingUnexistingHost(self): """Try to ping some unexisting host""" p = Pinger("1.0.1.0") self.assertFalse( p.ping() )
def test_PingGoogle(self): """Try to ping the Google.com""" p = Pinger("www.google.com") self.assertTrue( p.ping() )
def test_PingYourSelf(self): """Try to ping the localhost""" p1 = Pinger("localhost") p2 = Pinger("127.0.0.1") self.assertTrue( p1.ping() ) self.assertTrue( p2.ping() )