Advertisement
conformist

wifi-ap

Jan 28th, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.06 KB | None | 0 0
  1. #!/bin/bash
  2. #script to start/stop hostapd, dnsmasq, add/remove iptables rule
  3.  
  4. set -e
  5. exec 3>&1
  6. exec 2>&1 >> /tmp/wifi-ap
  7.  
  8. function print_help(){
  9.     echo "Start/Stop Software Access Point"
  10.     echo
  11.     echo "Usage `basename $0` options..."
  12.     echo "wifi-ap on to start Software AP"
  13.     echo "wifi-ap off to stop Software AP"
  14.     echo
  15.     echo "log-file - /tmp/wifi-ap"
  16.     echo
  17. }
  18. if [ $# = 0 ]; then
  19.     print_help >&3
  20.         exit 0
  21. fi
  22.  
  23. if [ $1 = on ]; then
  24.         ifconfig wlan0 192.168.2.1
  25.         service dnsmasq start
  26.         sysctl net.ipv4.ip_forward=1
  27.         iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
  28.         service hostapd start
  29.         notify-send --expire-time=4000 "Software Access Point" "<b>start</b>"
  30.     exit 0
  31. fi
  32.  
  33. if [ $1 = off ]; then
  34.         service dnsmasq stop
  35.         service hostapd stop
  36.         ifconfig wlan0 192.168.1.4
  37.         sysctl net.ipv4.ip_forward=0
  38.         iptables -D POSTROUTING -t nat -o ppp0 -j MASQUERADE
  39.         notify-send --expire-time=4000 "Software Access Point" "<b>stop</b>"
  40.     exit 0
  41. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement