Skip to content

Instantly share code, notes, and snippets.

@AlexisTM
Created September 7, 2018 15:35
Show Gist options
  • Save AlexisTM/c5acff7dec8323dd40a92c990a33555b to your computer and use it in GitHub Desktop.
Save AlexisTM/c5acff7dec8323dd40a92c990a33555b to your computer and use it in GitHub Desktop.
Adhoc alias example; to be sourced
adhoc() {
if [ -z ${1+x} ];
then echo -e "Run this using: \nadhoc on wlan0\nadhoc off";
return 1
else
ACTION=$1
WIFI_INTERFACE=$2
case $ACTION in
on|start)
[[ $WIFI_INTERFACE = "" ]] && echo Wifi interface missing && return 2
echo Starting Adhoc network on interface $WIFI_INTERFACE
echo 1 > sudo tee /proc/sys/net/ipv4/ip_forward
sudo service network-manager stop
sleep 1
sudo ip link set $WIFI_INTERFACE down
sudo iw $WIFI_INTERFACE set type adhoc
sudo iwconfig $WIFI_INTERFACE essid 'body'
sudo iwconfig $WIFI_INTERFACE key 1234567890
sudo ip link set $WIFI_INTERFACE up
sudo ip addr add 192.168.1.$ROBOT_ID/24 dev $WIFI_INTERFACE
iwlist $WIFI_INTERFACE scan > /dev/null
return 0
;;
off|stop)
echo Restarting network-manager
sudo service network-manager start
return 0
;;
*)
echo -e "Run this using: \nadhoc on wlan0\nadhoc off";
return 1
;;
esac
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment