Skip to main content
Solved

Find out any active ethernet adapter and disable it

  • November 17, 2017
  • 5 replies
  • 31 views

Forum|alt.badge.img+5

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!

Best answer by ruihere

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

5 replies

Forum|alt.badge.img+14
  • Valued Contributor
  • November 17, 2017

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


Forum|alt.badge.img+14
  • Valued Contributor
  • November 17, 2017

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


Forum|alt.badge.img+5
  • Author
  • New Contributor
  • Answer
  • November 17, 2017

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


Forum|alt.badge.img+5
  • Author
  • New Contributor
  • November 17, 2017

@tthurman we are thinking on the same route! haha


Forum|alt.badge.img+3

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