Created
October 19, 2010 16:52
-
-
Save glarizza/634552 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/env python | |
from SystemConfiguration import * | |
import syslog | |
interface = "en0" | |
store = SCDynamicStoreCreate(None, "global-network", None , None) | |
ifKey = "State:/Network/Interface/" + interface + "/IPv4" | |
keyStore = SCDynamicStoreCopyValue(store, ifKey) | |
# If the Print fails, then there's no IP Address for that interface and we can assume | |
# that the interface is in a down state - we return false | |
try: | |
print "The IP Address for interface: " + interface + " is: " + keyStore['Addresses'][0] | |
except TypeError: | |
syslog.syslog(syslog.LOG_ALERT, "Interface " + interface + " not active.") | |
return "false" | |
# The IP Address is returned in Unicode - beware of that | |
return keyStore['Addresses'][0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment