Created
January 7, 2011 19:51
-
-
Save glarizza/769994 to your computer and use it in GitHub Desktop.
This file contains 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/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