解析域名地址并生成win路由增强版

这个版本直接使用24位掩码生成网络路由, 前个版本只是生成主机路由. 可根据需要自行调整

#!/bin/sh
names="www.google.cm www.google.com code.google.com www.blogspot.com www.youtube.com  www.mail-archive.com 3.bp.blogspot.com www.geocities.jp bandao.cn haixiachina.com"
gw=192.168.100.10
network=""
netmask=""
via=""
dst=""
for name in $names; do
    address=`nslookup ${name} |grep Address |awk '{print $2}'|grep -v '#53'|xargs echo`
    echo "REM Add $name route for $address"
    #via=""
    for addr in $address; do
        network=`/bin/ipcalc ${addr}/28 -4 -n|sed 's/NETWORK=//g'`
        netmask=`/bin/ipcalc ${addr}/28 -4 -n|sed 's/NETMASK=//g'`
        #echo "route add $addr mask 255.255.255.255 $gw"
        #echo "route add $network mask $netmask $gw"
        if ! echo $via | grep -q ${network}; then
            via="$via ${network}"
        fi
    done
done
echo "REM via $via"
for dst in $via; do
    echo "route add $dst mask 255.255.255.0 $gw"
done
~


解析域名地址并生成win路由

你可能感兴趣的:(系统管理)