Skip to content

Instantly share code, notes, and snippets.

@glarizza
Created January 7, 2011 19:51
Show Gist options
  • Save glarizza/769994 to your computer and use it in GitHub Desktop.
Save glarizza/769994 to your computer and use it in GitHub Desktop.
#!/usr/bin/python2.5
#
# Grab BSD interface names for the first Airport and Ethernet interfaces on your computer.
#
import subprocess
ethTest = "networksetup -listnetworkserviceorder | awk -F': ' '/Ethernet,/ || /Ethernet .,/ {gsub(/\)/,\"\");print $3}'"
apTest = "networksetup -listnetworkserviceorder | awk -F': ' '/AirPort,/ {gsub(/\)/,\"\");print $3}'"
newdict = {}
command = subprocess.Popen(ethTest, shell=True, stdout=subprocess.PIPE,)
ethlist = command.communicate()[0]
newdict['Ethernet'] = ethlist.rstrip().split("\n")[0]
command = subprocess.Popen(apTest, shell=True, stdout=subprocess.PIPE,)
aplist = command.communicate()[0]
newdict['AirPort'] = aplist.rstrip().split("\n")[0]
print 'Ethernet interface is: ' + newdict['Ethernet']
print 'AirPort interface is: ' + newdict['AirPort']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment