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.
- Extracting MAC address using Python
- Python | Display images with PyGame
- Python program to find IP Address
- Python program to validate an IP Address
- Python | Count and display vowels in a string
- Python | Display text to PyGame window
- Check if email address valid or not in Python
- Python | Remove leading zeros from an IP address
- Change Object Display Name using __str__ function - Django Models | Python
- Difference between MAC Address and IP Address
- Address Calculation Sort using Hashing
- Local Broadcast and Loopback Address
- Program to display Astrological sign or Zodiac sign for given date of birth
- Important differences between Python 2.x and Python 3.x with examples
- Reading Python File-Like Objects from C | Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.