Created
December 21, 2015 23:51
-
-
Save flipsi/88d671cb05d948ff1ec2 to your computer and use it in GitHub Desktop.
Determine name of Wifi interface with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
try: | |
from netifaces import interfaces | |
except ImportError: | |
print("The python package netifaces is required.") | |
print("You can install it from the PyPI with ``pip install netifaces''.") | |
exit(1) | |
# array with names of interfaces | |
# e.g. ['lo', 'enp3s0', 'wlp7s0'] or ['lo', 'wlan0', 'virbr0'] | |
ifaces = interfaces() | |
# get the right one | |
name_old = 'wlan0' | |
name_new = 'wlp7s0' | |
try: | |
i = ifaces.index(name_old) | |
except ValueError: | |
i = ifaces.index(name_new) | |
print(ifaces[i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment