Skip to content

Instantly share code, notes, and snippets.

@inter-coder
Created April 9, 2017 18:44

Revisions

  1. inter-coder created this gist Apr 9, 2017.
    19 changes: 19 additions & 0 deletions DoesServiceExist.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #!/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")