Multiple ping script in Python

Try subprocess.call. It saves the return value of the program that was used. According to my ping manual, it returns 0 on success, 2 when pings were sent but no reply was received and any other value indicates an error. # typo error in import import subprocess for ping in range(1,10): address = “127.0.0.” + … Read more

Ping site and return result in PHP

function urlExists($url=NULL) { if($url == NULL) return false; $ch = curl_init($url); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($httpcode>=200 && $httpcode<300){ return true; } else { return false; } } This was grabbed from this post on how to check if a URL exists. Because … Read more

How to ping an IP address

InetAddress.isReachable() according to javadoc: “.. A typical implementation will use ICMP ECHO REQUESTs if the privilege can be obtained, otherwise it will try to establish a TCP connection on port 7 (Echo) of the destination host..”. Option #1 (ICMP) usually requires administrative (root) rights.

Pinging servers in Python

If you don’t need to support Windows, here’s a really concise way to do it: import os hostname = “google.com” #example response = os.system(“ping -c 1 ” + hostname) #and then check the response… if response == 0: print hostname, ‘is up!’ else: print hostname, ‘is down!’ This works because ping returns a non-zero value … Read more

Ping a site in Python?

See this pure Python ping by Matthew Dixon Cowles and Jens Diemer. Also, remember that Python requires root to spawn ICMP (i.e. ping) sockets in linux. import ping, socket try: ping.verbose_ping(‘www.google.com’, count=3) delay = ping.Ping(‘www.wikipedia.org’, timeout=2000).do() except socket.error, e: print “Ping Error:”, e The source code itself is easy to read, see the implementations of … Read more