zoukankan      html  css  js  c++  java
  • wifi_uplink脚本分析

    ~ >: vim apps/tools/wifi_uplink 
    #!/bin/sh
    # Copyright (C) 2012 GuoWenxue <guowenxue@gmail.com QQ:281143292>
    # This Shell scripts used to NAT by iptables, to make wlan0 as the downlink device
    # and set the uplink device as eth0/ppp0, it will be called by crond

    DOWNLINK_DEV="wlan0"

    #可以改为ppp0

    DEF_UPLINK_DEV="eth0"

    #使能profile和ifcfg-wlan0文件
    source /etc/profile
    source $network_cfg_dir/ifcfg-$DOWNLINK_DEV

    #在ifcfg-wlan0文件中有设置是否使用AP模式,如果没有就会在这里退出。
    if [ $WORKMODE != AP ] ; then
       echo "$DOWNLINK_DEV doesn't work as AP mode, exit now..."
       exit
    fi

    #求出子网的网络地址,例如wlan0的子网的ip=192.168.2.1
    NETWORK=`/bin/ipcalc -n $IPADDR_AP $NETMASK_AP`
    DOWNLINK_SUBNET=${NETWORK##*=}


    #set -x

    #取得默认网关的网卡
    #Current defaulte gateway out-going interface
    cur_gateway_inf=`ip route show | grep default | sed -n '1p' | awk -F "dev" '{print $2}'`


    #Current Uplink interface
    cur_uplink_inf=`iptables -t nat -vnL POSTROUTING | grep $DOWNLINK_SUBNET | awk '{print $7}'`


    #Initialise NAT or not


    if [ ! -n "$cur_uplink_inf" ]; then
        iptables -A INPUT -i $DOWNLINK_DEV -j ACCEPT
        if [ -n "$cur_gateway_inf" ] ; then
            iptables -t nat -A POSTROUTING -s $DOWNLINK_SUBNET -o $cur_gateway_inf -j MASQUERADE
        fi
        exit
    fi


    if [ $cur_uplink_inf != $cur_gateway_inf ] ; then
       iptables -t nat -D POSTROUTING -s $DOWNLINK_SUBNET -o $cur_uplink_inf -j MASQUERADE
       iptables -t nat -A POSTROUTING -s $DOWNLINK_SUBNET -o $cur_gateway_inf -j MASQUERADE
    fi

  • 相关阅读:
    URAL 1948 H
    int、long、long long取值范围
    Bonetrousle HackerRank 数学 + 思维题
    湖南省第十二届大学生计算机程序设计竞赛 problem A 2016
    Abbreviation ---- hackerrank
    POJ 3321 Apple Tree DFS序 + 树状数组
    HDU
    PICO CTF 2013 PHP 2: 85
    XSS进阶三
    XSS进阶二
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3221610.html
Copyright © 2011-2022 走看看