Skip to content

Instantly share code, notes, and snippets.

@afandian
Created January 20, 2011 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afandian/788639 to your computer and use it in GitHub Desktop.
Save afandian/788639 to your computer and use it in GitHub Desktop.
Ping Server
import web
import subprocess
urls = (
'/ping/(.*)/', 'ping'
)
app = web.application(urls, globals())
class ping:
def GET(self, ip):
result = subprocess.call(["ping", "-c", "1", ip])
# return code zero means that ping worked
if result == 0:
return "ok"
else:
return "not ok"
if __name__ == "__main__":
app.run()
@afandian
Copy link
Author

You will need to install web.py from http://webpy.org/ (that's easy). Run this by doing:

python pingserver.py 10000

then in your browser to go http://localhost:10000/ping/localhost/ (i.e. connect to server running on local machine and attempt to ping self).

Where the number is the port you want to run it on.

To go with https://gist.github.com/788658.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment