Skip to content

Instantly share code, notes, and snippets.

@flipsi
Created December 21, 2015 23:51
Show Gist options
  • Save flipsi/88d671cb05d948ff1ec2 to your computer and use it in GitHub Desktop.
Save flipsi/88d671cb05d948ff1ec2 to your computer and use it in GitHub Desktop.
Determine name of Wifi interface with Python
#!/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