Created
September 29, 2013 10:44
-
-
Save KorbenC/6751381 to your computer and use it in GitHub Desktop.
Test a connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import socket | |
| import time | |
| HOST="" | |
| PORT="" | |
| TIMEOUT=1.0 | |
| while True: | |
| try: | |
| s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| s.settimeout(TIMEOUT) | |
| s.connect((HOST, PORT)) | |
| print "[%s] Connection established" % time.strftime("%H:%M:%S") | |
| time.sleep(1) | |
| s.close() | |
| except: | |
| print "[%s] Cannot connect" % time.strftime("%H:%M:%S") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment