Find out any active ethernet adapter and disable it

ruihere
New Contributor II

Hi,

I try to disable any usb, usb-c, or other ways of ethernet and temperately disable it. let wifi run. and then reactive when I finish my script.

any way to find out active ethernet adapter and disable it?

thanks!

1 ACCEPTED SOLUTION

ruihere
New Contributor II

but even just change the service order, you need to know the name for the adapter?

actually I just found out how to do it:

a=$(networksetup -listnetworkserviceorder |grep 'Hardware Port' |grep '10/100' |grep -o '....$' |cut -c 1-3)
sudo ifconfig $a down

and later when I want it back, I use
sudo ifconfig $a up

maybe this long command can be simplify :)

View solution in original post

5 REPLIES 5

tthurman
Contributor III

I think this is going to be rather tricky. Primarily because it seems that each new adapter creates a new service.

Do you need to actually disable it? Can you just change the service order?

Regards
TJ

tthurman
Contributor III

However, if you need to do it.

What you're probably looking for is:
sudo networksetup -listallnetworkservices
sudo networksetup -setnetworkserviceenabled

example: sudo networksetup -setnetworkservice "Belkin USB-C LAN" off

ruihere
New Contributor II

but even just change the service order, you need to know the name for the adapter?

actually I just found out how to do it:

a=$(networksetup -listnetworkserviceorder |grep 'Hardware Port' |grep '10/100' |grep -o '....$' |cut -c 1-3)
sudo ifconfig $a down

and later when I want it back, I use
sudo ifconfig $a up

maybe this long command can be simplify :)

ruihere
New Contributor II

@tthurman we are thinking on the same route! haha

shigeru_okamoto
New Contributor II
New Contributor II

With the newer version of macOS, you might have to change '10/100' to 'Ethernet' to have the script work.