Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

givemesam

macrumors newbie
Original poster
Sep 21, 2016
2
0
can i get some help?

im trying to make a bash script that runs with a double click. its intended to do some rapid wifi networks cleanup. When run on a macbook, it should also clean up icloud linked phones too. neat.

The idea is to stop devices from network hopping when on the go, or at home etc.

Here is the equivalent windows one to get the idea. Can someone help me make a file that works on osx?

ECHO
netsh wlan delete profile name=*xfini*
netsh wlan delete profile name=*home-*
netsh wlan delete profile name=*netgear*
netsh wlan delete profile name=*dlink*
netsh wlan delete profile name=*d-link*
netsh wlan delete profile name=*centu*
netsh wlan delete profile name=*comca*
netsh wlan delete profile name=*hidden*.
netsh wlan delete profile name=*starb*
netsh wlan delete profile name=*goog*
netsh wlan delete profile name=*tull*
netsh wlan delete profile name=*t-mob*
netsh wlan delete profile name=*veriz*
netsh wlan delete profile name=*at&t*
netsh wlan delete profile name=*boingo*
PAUSE
 

mfram

Contributor
Jan 23, 2010
1,307
343
San Diego, CA USA
Unfortunately, it's not quite that easy on MacOS. There are commands to reconfigure your network, but it's not presented in quite the same fashion. The command "networksetup" controls the network configuration. You can use the command 'man networksetup' in a shell to understand all it can do.

First, you'd have to find the interface name for your WiFi adapter.

Code:
networksetup -listallhardwareports

Hardware Port: Wi-Fi
Device: en0
Ethernet Address: ac:bc:32:xx:xx:xx

You will need that 'en0' for the commands next. Get a list of known Wi-Fi networks:

Code:
networksetup -listpreferredwirelessnetworks en0

Preferred networks on en0:

    Chick-fil-A WiFi
    @Hyatt_WiFi
    FiOS-RPLVK

Then to remove them:

Code:
networksetup -removepreferredwirelessnetwork en0 "@Hyatt_WiFi"
Removed @Hyatt_WiFi from the preferred networks list

But it's going to ask you for a password every time. Or you can wrap it in 'sudo'

Code:
sudo networksetup -removepreferredwirelessnetwork en0 "FiOS-RPLVK"
Password:  *******
Removed FiOS-RPLVK from the preferred networks list

But either way, you will need a password at some point. As far as I can tell, there's no way to remove network names using a wildcard argument. You must give it the exact string. Of course, you could wrap the command line in a bash function which looks up the network names, does wildcard checking, then chooses the exact network name. Not impossible, but more coding.
 

Floris

macrumors 68020
Sep 7, 2007
2,381
1,473
Netherlands
Instead of a list of ranges you want to exclude, how about an array of stuff you frequent and want to keep instead?
 

givemesam

macrumors newbie
Original poster
Sep 21, 2016
2
0
hmm. i think the key is how osx will handle the wild cards. the idea is to pass around a file that will run right away, and be done with it. If it asks for a password to get started thats probobly ok too.

we could start with something that forgets 'xfinit' and 'home' and starbucks' for example

are we always going to run into an unknown interface name? is there a like 'findinterface *wi-fi* or *wlan* or *airport*'

==
so something like many lines of this

sudo networksetup -removepreferredwirelessnetwork en0 "xfinitywifi", "morenames," "list of more?",
#so we dont have to enter the password for each line command

and i do think finding that wifi = en0 may be a showstopper of its not always the first interface?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.