There are many ways to find hostname and IP address of a local machine. Here is a simple method 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 probably additional platforms.
Method used :
- gethostname() : The gethostname function retrieves the standard host name for the local computer.
- gethostbyname() : The gethostbyname function retrieves host information corresponding to a host name from a host database.
Hostname : pppContainer IP : 10.98.162.168
NOTE : Output varies machine to machine.
- Difference between MAC Address and IP Address
- Python | Count and display vowels in a string
- Display date and time in videos using OpenCV - Python
- Create and display a one-dimensional array-like object using Pandas in Python
- Display the Pandas DataFrame in table style and border around the table and not around the rows
- Python program to find IP Address
- Python | Remove leading zeros from an IP address
- Extracting MAC address using Python
- Check if email address valid or not in Python
- Python program to validate an IP Address
- Python script to change MAC address of Linux machine
- Python program to determine if the given IPv4 Address is reserved using ipaddress module
- Python program to determine if the given IP Address is Public or Private using ipaddress module
- Python program to find if two IP Address belongs to Same or Different Network
- Extract IP address from file using Python
- Python script to get device vendor name from MAC Address
- Python - Extract domain name from Email address
- Application to get address details from zip code Using Python
- Python | Display images with PyGame
- Python | Display text to PyGame window
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.