Advertisement
j0lly

share internet

Mar 29th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.01 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # defaults
  4. WAN=ppp0
  5. LAN=wlan0
  6. LANIP="192.168.133.1"
  7. DHCPR="192.168.133.2,192.168.133.254"
  8. DNS="208.67.222.222,8.8.4.4"
  9.  
  10. RED=$(tput setaf 1 && tput bold)
  11. GREEN=$(tput setaf 2 && tput bold)
  12. STAND=$(tput sgr0)
  13. BLUE=$(tput setaf 6 && tput bold)
  14.  
  15. usage() {
  16.     echo "USAGE: $0 [-v][-d] [WAN=$WAN] [LAN=$LAN] [LANIP=$LANIP] [DHCPR=$DHCPR]"
  17.     echo "USAGE: $0 [-v][-d] [WAN=$WAN] [LAN=$LAN] # disable forwarding"
  18.     echo "USAGE: $0 [-v][-l] # print status"
  19.     echo "defaults: WAN=ppp0 LAN=wlan0 LANIP=192.168.133.1 DNS=8.8.8.8,8.8.4.4 DHCPR=192.168.133.2,192.168.133.254"
  20. }
  21.  
  22. list() {
  23.     echo "Forwarding information"
  24.     iptables -L
  25.     echo ""
  26.     iptables -L -t nat
  27.     echo -e "\n/proc/sys/net/ipv4/ip_forward: $(cat /proc/sys/net/ipv4/ip_forward)"
  28. }
  29.  
  30. listsettings() {
  31.     echo "WAN=$WAN, LAN=$LAN LANIP=$LANIP DHCPR=$DHCPR"
  32. }
  33.  
  34. # setup forwarding and the dnsmasq service
  35. fwd() {
  36.     sysctl -w net.ipv4.ip_forward=1
  37.    
  38.     # Put the interface in Ad-hoc mode
  39.     iwconfig $LAN mode Ad-Hoc
  40.    
  41.     # Set the essid for the access point
  42.     iwconfig $LAN essid TheH0le
  43.  
  44.     # Set auto channel
  45.     iwconfig $LAN channel auto
  46.  
  47.     # Set the security (WEP)
  48.  
  49.     # Set Key
  50.     #iwconfig $LAN key restricted s:0x000
  51.  
  52.     # Set encryption
  53.     #iwconfig $LAN key on
  54.      
  55.    
  56.     ifconfig $LAN $LANIP/24 netmask 255.255.255.0 up
  57.    
  58.     #iptables -A FORWARD -o $WAN -i $LAN -s $LANIP/24 -m conntrack --ctstate NEW -j ACCEPT
  59.     #iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
  60.     #iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE
  61.     iptables-restore < /home/0x00/rules
  62.  
  63.    
  64.     /usr/bin/dnsmasq -C /dev/null > /dev/null 2>&1 \
  65.         --domain-needed \
  66.         --bogus-priv \
  67.         --interface=$LAN \
  68.         --dhcp-option=6,$DNS \
  69.         --listen-address=$LANIP \
  70.         --dhcp-range=$DHCPR,12h \
  71.        
  72.     echo "to disable: $0 -d"
  73. }
  74.  
  75. # remove forwarding and the dnsmasq service
  76. unfwd() {
  77.     pkill -9 dnsmasq
  78.     ifconfig $LAN down
  79.  
  80.     sysctl -w net.ipv4.ip_forward=0
  81.  
  82.     #iptables -D FORWARD -o $WAN -i $LAN -s $LANIP/24 -m conntrack --ctstate NEW -j ACCEPT
  83.     #iptables -D FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
  84.     iptables -F
  85.    
  86.     iwconfig $LAN mode managed
  87. }
  88.  
  89. # calculate DHCPR
  90. mkrange() {
  91.     PRE=$(echo $LANIP | cut -d. -f-3)
  92.     SUF=$(echo $LANIP | cut -d. -f4)
  93.     DHCPR="$PRE.$(($SUF+1)),$PRE.253"
  94. }
  95.  
  96. #--------
  97.  
  98. for arg in "$@"
  99. do
  100.     case "$arg" in
  101.         WAN=*|LAN=*|LANIP=* )
  102.             eval $arg
  103.             ;;
  104.         DHCPR=* )
  105.             eval $arg
  106.             DHCPFLAG=true
  107.             ;;
  108.         -d )
  109.             echo "deleting forwarding"
  110.             DISABLE=true
  111.             ;;
  112.         -l )
  113.             LIST=true
  114.             ;;
  115.         -v )
  116.             VERBOSE=true
  117.             ;;
  118.         * )
  119.             usage
  120.             exit 0
  121.             ;;
  122.     esac
  123. done
  124.  
  125.  
  126. [ $DHCPFLAG ]   || mkrange
  127. [ $VERBOSE ]    && listsettings
  128. [ $LIST ]       && list && exit 1
  129.  
  130. if [ ! $DISABLE ] ; then
  131.     fwd
  132. else
  133.     unfwd
  134. fi
  135. eri
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement