getip.sh

来自「shell 简单例程,含数学计算IP获取awk例程字数统计示例」· Shell 代码 · 共 28 行

SH
28
字号
#!/bin/bash# getip.sh -- get an usable ipaddress automatically# author: falcon <zhangjinw@gmail.com># update: Tue Oct 30 23:46:17 CST 2007net="192.168.1"default_gateway="192.168.1.239"over_time=2# check the current ipaddressping -c 1 $default_gateway -W $over_time[ $? -eq 0 ] && echo "the current ipaddress is okey\!" && exit -1;while :; do	# clear the current configuration        ifconfig eth0 down        # configure the ipaddress of the eth0        ifconfig eth0 \                $net.$(($RANDOM /130 +2)) \                up         # configure the default gateway        route add default gw $default_gateway        # check the new configuration        ping -c 1 $default_gw -W $over_time        # if work, finish        [ $? -eq 0 ] && breakdone

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?