help making a bash script / wifi cleanup

Discussion in 'macOS' started by givemesam, Sep 21, 2016.

  1. givemesam macrumors newbie

    Joined:
    Sep 21, 2016
    #1
    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
     
  2. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #2
    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.
     
  3. Floris macrumors 68020

    Floris

    Joined:
    Sep 7, 2007
    Location:
    Netherlands
    #3
    Instead of a list of ranges you want to exclude, how about an array of stuff you frequent and want to keep instead?
     
  4. givemesam thread starter macrumors newbie

    Joined:
    Sep 21, 2016
    #4
    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?
     

Share This Page