hbutils.system.network

Overview:

Some useful tools for network.

hostfile

hbutils.system.network.hostfile() → str[source]
Overview:

Get host file in this os.

Returns:

Host file path in this os.

Note

This should be /etc/hosts on Linux and macOS, but c:\windows\system32\drivers\etc\hosts on Windows.

get_hosts

hbutils.system.network.get_hosts() → Dict[str, str][source]
Overview:

Get hosts content in form of dictionary.

Returns:

A dictionary of the hosts file.

Examples::
>>> from hbutils.system import get_hosts
>>> get_hosts()
{'hansbug-VirtualBox': '127.0.0.1', 'localhost': '127.0.0.1'}

get_localhost_ip

hbutils.system.network.get_localhost_ip() → str[source]
Overview:

Get ip address of localhost. It will be checked in hosts, and just return 127.0.0.1 is not found.

Returns:

IP address of localhost.

Examples::
>>> from hbutils.system import get_localhost_ip
>>> get_localhost_ip()
'127.0.0.1'