Posted on 07-25-2022 05:29 PM
Hello Guys, I have been trying to disable the Ethernet / LAN connection to our end users and only enable WIFI but my script seems to be not working well. Do you mind sharing your scripts or changes from your end?
Here's my script that i also found here.
#!/bin/bash
validConnections=("Ethernet" "Wi-Fi" "USB Ethernet"
"Broadcom NetXtreme Gigabit Ethernet Controller"
"Display Ethernet"
"Thunderbolt Bridge"
"Thunderbolt Ethernet")
while read connection; do
if [[ $(echo "${validConnections[@]}" | grep "$connection") ]]; then
setting=$(networksetup -getautoproxyurl "$connection" | awk '/Enabled/{print $NF}')
if [[ "$setting" == "No" ]]; then
Disabled+=("$connection")
elif [[ "$setting" == "Yes" ]]; then
Enabled+=("$connection")
fi
fi
done < <(networksetup -listallhardwareports | awk -F': ' '/Hardware Port:/{print $NF}')
if [[ -z "${Disabled[@]}" ]]; then
echo "<result>Yes</result>"
else
echo "<result>No</result>"
fi
Posted on 07-25-2022 09:34 PM
What you've posted is an Extension Attribute script, not a script you would use to make actual changes to endpoints. You can tell it's an Extension Attribute by the echo "<result>Yes</result>" and echo "<result>No</result>" lines. So all it's doing is outputting the result of checking if any connections are enabled/disabled or not. And furthermore, this line - networksetup -getautoproxyurl - means it's specifically checking if auto proxy URL is enabled/disabled for any of the connections. There's nothing in the script that would be disabling an Ethernet connection.
To do what you want, the script can be very simple. For example:
#!/bin/zsh
while read connection; do
/bin/echo "Disabling $connection"
/usr/sbin/networksetup -setnetworkserviceenabled "$connection" off
done < <(/usr/sbin/networksetup -listallhardwareports | /usr/bin/awk -F': ' '/Hardware Port:/{print $NF}' | /usr/bin/grep -i "Ethernet")