code: def _can_connect(ip, port):
      
      cs = socket.socket()
      try:
          cs.connect((ip, port))
          cs.close()
          return True
      except socket.error:
          return False
docs: Checks if a TCP port at IP address is possible to connect to