Coder Social home page Coder Social logo

vborodulin / wifi-loc-control Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 3.0 12 KB

Allows you to change your macOS network location automatically based on the Wi-Fi network name (SSID) you are connected to

License: MIT License

Shell 100.00%
macos utility wifi

wifi-loc-control's Introduction

WiFiLocControl

WiFiLocControl allows you to change your macOS network location automatically based on the Wi-Fi network (SSID) you are connected to. It is particularly useful for users who use Wi-Fi at work and at home, but the network settings (for example, custom DNS configurations) you use at work don't allow your Mac to automatically connect to the same type of network at home.

Features

  • Automatically changes network locations based on current Wi-Fi name.
  • Supports alias configurations for multiple Wi-Fi names.
  • Executes location-specific scripts.

Installation

  1. Clone the repository to your local machine.

    git clone https://github.com/vborodulin/wifi-loc-control.git
    cd ./wifi-loc-control
  2. Run the bootstrap script to set up the environment.

    ./bootstrap.sh    

    It will ask you for a root password to install WiFiLocControl to the /usr/local/bin directory.

Usage

To set up specific preferences for your Wi-Fi networks, keep it easy: just name your network locations after your Wi-Fi names. For example, if you want special settings for My_Home_Wi-Fi_5GHz, make a location called My_Home_Wi-Fi_5GHz. When you connect to that Wi-Fi, your location will switch automatically. If you connect to a Wi-Fi without a special name, it defaults to Automatic.

Configuration

Aliasing

If you want to share one network location between different wireless networks (for instance, you have a wireless router which broadcasts on 2.4 and 5GHz bands simultaneously), then you can create a configuration file ~/.wifi-loc-control/alias.conf (plain text file with simple key-value pairs, no spaces in between):

My_Home_Wi-Fi_5GHz=Home
My_Home_Wi-Fi_2.4GHz=Home

Where the keys are the wireless network names and the values are the desired location names.

Run Scripts on Wi-Fi Network Connection

Sometimes you want to execute a script every time you connect to a specific Wi-Fi network. For example enable stealth or enable firewall mode. Follow these steps:

  • Place your scripts in ~/.wifi-loc-control/.
  • Name the scripts after the Wi-Fi network name, ensuring consistency with the corresponding network locations.

Example script (~/.wifi-loc-control/My_Home_Wi-Fi_5GHz):

#!/usr/bin/env bash
# Collect all output from this script to ~/Library/Logs/WiFiLocControl.log
exec 2>&1

# Enable stealth mode which makes your computer less visible to potential attackers
/usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on

To reset changes made by specific location scripts, create corresponding reset script. Example reset script (~/.wifi-loc-control/Automatic):

#!/usr/bin/env bash
exec 2>&1

# Disable stealth mode which makes your computer less visible to potential attackers
/usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off

Make scripts executable

chmod +x ~/.wifi-loc-control/My_Home_Wi-Fi_5GHz
chmod +x ~/.wifi-loc-control/Automatic

Troubleshooting

Rich logs available at ~/Library/Logs/WiFiLocControl.log.

tail -f ~/Library/Logs/WiFiLocControl.log

Logs examples:

[2023-11-26 13:44:49] current wifi_name 'My_Home_Wi-Fi_5GHz'
[2023-11-26 13:44:49] network locations: Automatic Home
[2023-11-26 13:44:49] current network location 'Automatic'
[2023-11-26 13:44:49] reading alias config '/Users/vborodulin/.wifi-loc-control/alias.conf'
[2023-11-26 13:44:49] for wifi name 'My_Home_Wi-Fi_5GHz' found alias 'Home'
[2023-11-26 13:44:49] location switched to 'Home'
[2023-11-26 13:44:49] finding script for location 'Home'
[2023-11-26 13:44:49] running script '/Users/vborodulin/.wifi-loc-control/Home'

Contributing

Contributions are welcome! If you have suggestions, improvements, or encounter issues, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License.

wifi-loc-control's People

Contributors

borodalivexp avatar medformatik avatar ollisulopuisto avatar vborodulin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

wifi-loc-control's Issues

Empty WiFi Name

I've run rich logs, and it looks like the wifi_name function isn't working as expected:

[2024-03-08 15:28:03] current wifi_name ''
[2024-03-08 15:28:03] wifi_name is empty

Any ideas on how to fix this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.