Using Python to check if remote port is open and accessible.
Taken from http://snipplr.com/view/19639/test-if-an-ipport-is-open/
| import time | |
| import socket | |
| ip = "mylicenseserver.mydomain.com" | |
| port = 27000 | |
| responses = [] | |
| for i in range(10): | |
| try: | |
| s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| s.settimeout(1) | |
| s.connect((ip, port)) | |
| responses.append("{} is UP".format(ip)) | |
| except: | |
| time.sleep(1) | |
| finally: | |
| try: | |
| s.shutdown(socket.SHUT_RDWR) | |
| s.close() | |
| except OSError: | |
| responses.append("{} is DOWN".format(ip)) | |
| results = "\n".join(responses) | |
| if "DOWN" in results: | |
| print("Server is down.") | |
| else: | |
| print("Server is up!") |
Using Python to check if remote port is open and accessible.
Taken from http://snipplr.com/view/19639/test-if-an-ipport-is-open/