auto_change_ip.sh-创新互联

#!/bin/bash
#2019年11月6日14:04:34
#by author andy
IP_STATUS=cat /etc/sysconfig/network-scripts/ifcfg-eth0 | awk '/BOOTPROTO/ {print $0}'
IP=ifconfig eth0 | awk '/broadcast/ {print $0}'| awk -F' ' '{print $2}'
IP_PATH="/etc/sysconfig/network-scripts/ifcfg-eth0"
if [ $IP_STATUS == "BOOTPROTO=static" ]; then
echo "The $IP is static,Please input ip address if your want to change it;Don't change it Please enter "Ctrl+c" to EXIT.."

信阳ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!
while  true
 read -p "Please input your ip address:" Address
 count=(`echo "$Address" | grep -v "Aa-Zz" | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | awk -F. '{print $1,$2,$3,$4}' `)
        IP1=${count[0]}
    IP2=${count[1]}
    IP3=${count[2]}
    IP4=${count[3]}
do
    if [[ $IP1 -eq 10  &&  $IP2 -eq 0 && $IP3 -eq 0 &&  $IP4 -ge 10 && $IP4 -le 20 ]] ;then
            echo "$IP1 First  is right "
            echo "$IP2 Second is right "
            echo "$IP3 Third  is right "
            echo "$IP4 Fourth is right "    
        echo "It is chenging the IP ,Wait a moment... "
        sed -i '/IPADDR/s/'${IP}'/'${Address}'/g' $IP_PATH
        if [ $? == 0 ]; then
                /etc/init.d/network restart
            echo "IP already chenge to $Address"
        else    
            echo "has a error"
            exit 
        fi
        exit 
    else
            echo "IP first   number must be 10,Please change!"
            echo "IP Second  number must be 0,Please change!"
            echo "IP Third   number must be 0,Please change!"
            echo "IP Fourth  number must be 10-20,Please change!"
    fi
done

elif [ $IP_STATUS == "BOOTPROTO=dhcp" ]; then
echo "The $IP is dhcp,Please input unmber if your want to change it;Don't change it Please enter "Ctrl+c" to EXIT.."
to_static(){
while true
read -p "Please input your ip address:" Address
count=(echo "$Address" | grep -v "Aa-Zz" | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | awk -F. '{print $1,$2,$3,$4}')
IP1=${count[0]}
IP2=${count[1]}
IP3=${count[2]}
IP4=${count[3]}
do
if [[ $IP1 -eq 10 && $IP2 -eq 0 && $IP3 -eq 0 && $IP4 -ge 10 && $IP4 -le 20 ]] ;then
echo "$IP1 First is right "
echo "$IP2 Second is right "
echo "It is chenging the IP ,Wait a moment... "
sed -i '/BOOTPROTO/s/BOOTPROTO=dhcp/BOOTPROTO=static/g' $IP_PATH
sed -i '/NETMASK/s/NETMASK=/NETMASK=255.255.255.0/g' $IP_PATH
sed -i '/GATEWAY/s/GATEWAY=/GATEWAY=10.0.0.2/g' $IP_PATH
sed -i '/IPADDR/s/IPADDR=/IPADDR='${Address}'/g' $IP_PATH
if [ $? == 0 ]; then
/etc/init.d/network restart
echo "IP already chenge to $Address"
else
echo "has a error"
exit
fi
exit
else
echo "IP first number must be 10,Please change!"
echo "IP Second number must be 0,Please change!"
echo "IP Third number must be 0,Please change!"
echo "IP Fourth number must be 10-20,Please change!"
fi
exit
done
}
$i
PS3="Please select your number:"
select i in to_static nothing_go
do
case $i in
to_static)
to_static
;;
nothing_go)
exit 1
exit
esac
done

fi

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文名称:auto_change_ip.sh-创新互联
本文网址:http://bzwzjz.com/article/ddocjp.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 成都网站建设流程 专业网站设计 营销型网站建设 攀枝花网站设计 上市集团网站建设 手机网站制作 成都品牌网站设计 营销型网站建设 网站建设 成都网站建设 营销型网站建设 成都网站建设 网站建设 成都网站建设 成都网站设计 app网站建设 重庆网站建设 成都网站建设 营销网站建设 古蔺网站建设 重庆电商网站建设 网站制作