Skip to content

Instantly share code, notes, and snippets.

@richard-mihalovic
Created January 11, 2017 10:27
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 richard-mihalovic/61f9d52f77280130469a69498d481a5e to your computer and use it in GitHub Desktop.
Save richard-mihalovic/61f9d52f77280130469a69498d481a5e to your computer and use it in GitHub Desktop.
import socket
def has_mongodb(host, port=27017):
try:
host_addr = socket.gethostbyname(host)
if not host_addr:
return False
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
s.connect((host, port))
s.close()
except KeyboardInterrupt:
raise
except:
return False
return True
print(has_mongodb('domain.tld')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment