-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinterfaces.py
More file actions
executable file
·48 lines (40 loc) · 1.28 KB
/
interfaces.py
File metadata and controls
executable file
·48 lines (40 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python
from SystemConfiguration import (
SCNetworkInterfaceGetBSDName,
SCNetworkInterfaceGetLocalizedDisplayName,
SCNetworkInterfaceGetHardwareAddressString,
SCNetworkServiceGetName,
SCNetworkInterfaceCopyAll,
SCPreferencesCreate,
SCNetworkServiceCopyAll
)
def hasEN(item):
if 'en' in item:
return True
else:
return False
def get_networkinterfacelist(network_interfaces):
'''Returns a list of all network interface names'''
d = {}
for interface in network_interfaces:
bsdName = SCNetworkInterfaceGetBSDName(interface)
if 'en' in bsdName:
d[SCNetworkInterfaceGetLocalizedDisplayName(interface)] = (
bsdName,
SCNetworkInterfaceGetHardwareAddressString(interface)
)
return d
def get_networkservices(network_services):
'''Returns a list of all network interface names'''
l = []
for service in network_services:
l.append(SCNetworkServiceGetName(service))
return l
def main():
network_interfaces = SCNetworkInterfaceCopyAll()
print get_networkinterfacelist(network_interfaces)
prefs = SCPreferencesCreate(None, 'foo', None)
network_services = SCNetworkServiceCopyAll(prefs)
print get_networkservices(network_services)
if __name__ == "__main__":
main()