Created
April 9, 2017 18:44
-
-
Save inter-coder/74d3113404ac3ff31255aa8af380d25b to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Determining whether the services are working at a remote location | |
from socket import * | |
def DoesServiceExist(host, port): | |
targetIP = gethostbyname(host) | |
s = socket(AF_INET, SOCK_STREAM) | |
s.settimeout(1) | |
result = s.connect_ex((targetIP,port)) | |
s.close() | |
if(result == 0) : | |
return True | |
return False | |
#example | |
if DoesServiceExist("smtp.gmail.com",465): | |
print("YES mail server is UP") | |
else: | |
print("NO mail server is DOWN") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python code for determining whether the services are working at a remote location