-
-
Save madlymad/045faf19e663ec1243f0798e1cbe2004 to your computer and use it in GitHub Desktop.
Routing all traffic to particular IP address via wifi network interface on MacOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# NOTE: wifi/ethernet network interface is: en1 | |
net_interface=en1 | |
mac_network_interface=ifconfig $net_interface ether | sed -nl 's/\w*ether \([^ ]*\).*/\1/p' | sed 's/:/./g' | |
wifi_router=netstat -nr | grep default | grep $net_interface | perl -nle '/(\d+\.\d+\.\d+\.\d+)/ && print $1' | |
wifi_address=$net_interface:$mac_network_interface | |
TOADDR=`ifconfig $net_interface inet | sed -nl 's/\w*inet \([^ ]*\).*/\1/p'` | |
TO=`echo -n ${TOADDR//[[:space:]]}` | |
echo "ADDING ROUTE TO $1 VIA $net_interface: $TO" | |
route -n add -host $1 $wifi_router -ifp $wifi_address -ifa $TO -static | |
echo "" | |
echo "ROUTE ADDED:" | |
route get $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment