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 program to find IP Address
- Python program to validate an IP Address
- Python | Remove leading zeros from an IP address
- Check if email address valid or not in Python
- Python | Display images with PyGame
- Python | Count and display vowels in a string
- Python | Display text to PyGame window
- 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
- Reading Python File-Like Objects from C | Python
- Important differences between Python 2.x and Python 3.x with examples
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.