forked from jamf/Jamf-Nation-Extension-Attributes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Active_Network_Interface.xml
44 lines (44 loc) · 1.78 KB
/
Active_Network_Interface.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<extensionAttribute>
<displayName>Active Network Interface</displayName>
<description/>
<dataType>string</dataType>
<scriptContentsMac>#!/bin/bash
ref=$(/usr/bin/sw_vers -productVersion | awk '{print substr($1,4,2)}')
case $ref in
[0-4] ) ntwkset="/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -listnetworkserviceorder"
;;
*) ntwkset="networksetup -listnetworkserviceorder"
;;
esac
ifconfigoutput='
BEGIN { print_it = 0 }
/status: active/ { print_it = 1 }
/^($|[^\t])/ { if(print_it) print buffer; buffer = $0; print_it = 0 }
/^\t/ { buffer = buffer "\n" $0 }
END { if(print_it) print buffer }
'
ntwkint=($(ifconfig -u | awk "$ifconfigoutput" | awk '/flags/{print substr($1,1,3)}'))
/bin/echo -n $"<result>"
for x in "${ntwkint[@]}"
do
echo `$ntwkset | grep "$x" | sed -e 's/[)(]//g;s/,//g;s/.*Port: //g;s/Device:\ //g'`
done
echo "</result>"</scriptContentsMac>
<scriptContentsWindows>On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration",,48)
intmetric = 999
For Each objItem in colItems
If objitem.ipenabled = True then
If objItem.IPConnectionMetric < intmetric then
stractiveconnection = objItem.description
intmetric = objItem.IPConnectionMetric
End If
End If
Next
WScript.Echo "<result>" & stractiveconnection & "</result>"</scriptContentsWindows>
</extensionAttribute>