4 examples of 'python ping test' in Python

Every line of 'python ping test' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
49@tornado.testing.gen_test
50def test_ping(self):
51 c = Client()
52 yield c.connect()
53 res = yield c.call('PING')
54 self.assertEqual(res, b"PONG")
55 c.disconnect()
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

29def testSimple(self):
30 client = self.backend.client
31 request = client.ping()
32 self.assertEqual(request.command_name, 'PING')
33 self.assertEqual(str(request), 'PING')
34 yield request
35 self.assertEqual(request.result, True)
36 request = client.echo('ciao')
37 self.assertEqual(str(request), "ECHO('ciao',)")
38 yield request
39 self.assertEqual(request.result, b'ciao')
7def ping(host, count=1, timeout=1):
8 cmd = [
9 'ping',
10 '-c',
11 str(count),
12 '-w',
13 str(timeout),
14 host,
15 ]
16
17 sub = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
18 sub.communicate()
19 ret = sub.wait() == 0
20 return ret
105def ping(host, timeout=1):
106 # timeout=1 means: If one second goes by without a reply from the server,
107 # the client assumes that either the client's ping or the server's pong is lost
108 dest = gethostbyname(host)
109 print("Pinging " + dest + " using Python:")
110 print("")
111 # Send ping requests to a server separated by approximately one second
112 while True :
113 delay = doOnePing(dest, timeout)
114 print(delay)
115 time.sleep(1)# one second
116 return delay

Related snippets