Shell脚本批量添加IP方法

2014/12/1821:30:21 发表评论
#!/bin/bash
#网络文件
networkfile="/etc/sysconfig/network-scripts/ifcfg-eth0"
#虚拟网卡数
virtul_eth=3
baseaddress="192.168.0"
#从237开始扫描IP地址
baseip="237"
while [ 1 ]
do
    if [ $baseip -gt 254 ];then
        break
    fi
    ping -c2 ${baseaddress}.${baseip}
    if [ "x$?" != "x0" ]
    then
        echo "Congratuations!IP:[${baseaddress}.${baseip}] not be used yet!" >> iplist.txt
#找以同人占用IP就添加到虚拟网卡,做为自己的独立IP
        cp ${networkfile} ${networkfile}:${virtul_eth}
        grep -E -v "DEVICE|IPADDR" ${networkfile}:${virtul_eth} > 1.txt
        echo "DEVICE=eth0:$virtul_eth" >>1.txt
        echo "IPADDR=${baseaddress}.${baseip}" >> 1.txt
        mv -f 1.txt ${networkfile}:${virtul_eth}
    else
        echo "Bad IP:[${baseaddress}.${baseip}]"
    fi
    baseip=$(expr ${baseip} + 1)
    virtul_eth=$(expr ${virtul_eth} + 1)
done

  • 微信扫码赞助
  • weinxin
  • 支付宝赞助
  • weinxin

发表评论

您必须才能发表评论!