Python Methods and Functions
There are many ways to find the hostname and IP address of the local machine. Here is an easy way to find hostname and IP address using Python code.
Library used — socket : This module provides access to the BSD socket interface. It is available on all modern Unix systems, Windows, MacOS and possibly additional platforms.
- gethostname () : The gethostname function retrieves the default hostname for the local computer. li>
- gethostbyname () : The gethostbyname function retrieves the hostname information corresponding to the hostname from the host database.
"Unable to get Hostname and IP"
Output: p >
Hostname: pppContainer IP: 10.98.162.168
NOTE . Power depends on the machine.