#!/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
This comment has been minimized.
inter-coder commentedApr 9, 2017
Python code for determining whether the services are working at a remote location