schrodinger.utils.net module

Helpers for network operations.

schrodinger.utils.net.shorthost(hostname)

Return the short hostname for the given hostname, without the domain name. If hostname is an IP address, it is returned unmodified.

schrodinger.utils.net.hostname_is_local(hostname)

Determine whether the given hostname refers to the current host.

schrodinger.utils.net.safe_server_address_filename(addr: str) str

Try to simplify and make a server address safe for use in a filename. Uses the shorthost, and replaces colons with underscores.

For example, nyc-license-server.example.com:8080 becomes nyc-license-server_8080.

Parameters

addr – server address in the form ‘hostname:port’

Raises

ValueError

schrodinger.utils.net.is_ipv4_addr(addr)

Determine whether the given string is an IPv4 address.

schrodinger.utils.net.hostname_and_port(addr, default_port=None)

Get the hostname and port of the provided address. If no port is provided, return the provided default, or None.

Returns

a tuple of address and port

Return type

(str, int | None)

schrodinger.utils.net.join_host_port(hostname: str, port: Union[str, int]) str

Join a hostname and port into a network address. Taken from the Go implementation of net.JoinHostPort.

schrodinger.utils.net.validate_connection(host, port, timeout=None)

Attempt to connect to a specified host and port.

Parameters
  • host (str) – the host to connect to

  • port (int) – the port to connect to

Returns

a 2-tuple describing whether the connection was successful, and if not, an error message

Return type

tuple(bool, str)

schrodinger.utils.net.get_hostnames(logger: logging.Logger) list[str]

Get a list of all available hostnames corresponding to the current machine.

Parameters

logger – the logger to use, writes debug messages