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 | Display images with PyGame
- Check if email address valid or not in Python
- Python | Remove leading zeros from an IP address
- Python | Count and display vowels in a string
- Python | Display text to PyGame window
- Python program to find if two IP Address belongs to Same or Different Network
- Display date and time in videos using OpenCV - Python
- Change Object Display Name using __str__ function - Django Models | Python
- Difference between MAC Address and IP Address
- PyQt5 - GUI Application to get IP address
- Local Broadcast and Loopback Address
- How to validate MAC address using Regular Expression
- Address Calculation Sort using Hashing
- PyQt5 | How to display decimal values in Progress Bar ?
- PyQt5 QSpinBox - Access display integer base
- PyQt5 QSpinBox - Setting display integer base
- Program to display Astrological sign or Zodiac sign for given date of birth
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.