def try_address(host, port=0, family=socket.AF_INET):
 try:
  sock = socket.socket(family, socket.SOCK_STREAM)
  sock.bind((host, port))
 except (socket.error, socket.gaierror):
  return False
 else:
  sock.close()
  return True

def try_address ( host , port = 0 , family = socket . AF_INET ) : try : sock = socket . socket ( family , socket . SOCK_STREAM ) sock . bind ( ( host , port ) ) except ( socket . error , socket . gaierror ) : return False else : sock . close ( ) return True
try to bind a socket on the given host:port and return true if that has been possible .