def can_connect(ip, port):
 try:
  socket.create_connection((ip, port))
 except socket.error as e:
  if (e.errno not in {errno.ECONNREFUSED, errno.ETIMEDOUT}):
   app_log.error('Unexpected error connecting to %s:%i %s', ip, port, e)
  return False
 else:
  return True

def can_connect ( ip , port ) : try : socket . create_connection ( ( ip , port ) ) except socket . error as e : if ( e . errno not in { errno . ECONNREFUSED , errno . ETIMEDOUT } ) : app_log . error ( 'Unexpected error connecting to %s:%i %s' , ip , port , e ) return False else : return True
check if we can connect to an ip:port return true if we can connect .