Disable Ethernet Port

TDManila
New Contributor II

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

4 REPLIES 4

mm2270
Legendary Contributor III

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")

 

 

A ethernet (Lan server) connection makes the WiFi disable automatically in windows 8.1. By switching on the WiFi manually let only WiFi to run for few moments and the WiFi goes off again.

Adrianmadrid
New Contributor

To disconnect your wired Ethernet connection, unplug your Ethernet cable from its jack. On the Windows taskbar (bottom, right), right-click the Wireless Network Connection icon and select Disable. On the menu bar (top, right), right click the wireless icon and select Turn AirPort Off.

Adrianmadrid
New Contributor

A ethernet (Lan server) connection makes the WiFi disable automatically in windows 8.1. By switching on the WiFi manually let only WiFi to run for few moments and the WiFi goes off again.