A lightweight and cross-platform Python library to retrieve network interface names with a simple API.
Find on PyPI - https://pypi.org/project/netinterfaces/
- Single-function API – Quickly retrieve network interface names with minimal effort.
- Cross-platform support – Works on Windows, Linux, and macOS.
- No external dependencies – Pure Python implementation with no additional requirements.
- Consistent output format – Provides a uniform list output across different operating systems.
- Handles errors gracefully – Returns an empty list in case of errors instead of crashing.
Install netinterfaces using pip:
pip install netinterfacesImport and use get_interfaces to retrieve network interface names:
from netinterfaces import get_interfaces
interfaces = get_interfaces()
print(interfaces) # Example output: ['eth0', 'wlan0', 'lo']The library adapts to different platforms and returns interface names accordingly:
- Linux:
['lo', 'eth0', 'wlan0'] - Windows:
['Ethernet', 'Wi-Fi', 'Loopback Pseudo-Interface'] - macOS:
['lo0', 'en0', 'en1']
def get_interfaces() -> list:
"""
Retrieves a list of network interface names available on the system.
Returns:
list: A list of network interface names (e.g., ['eth0', 'wlan0', 'lo']).
If an error occurs, an empty list is returned.
"""- List of strings: Each string represents a network interface name.
- Empty list: Returned in case of an error (e.g., lack of permissions, unexpected system behavior).
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch (
feature-branch). - Implement your changes and write tests if necessary.
- Submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have feature requests, please open an issue on the GitHub repository.