您尚未登录。

#1 2016-12-01 22:02:21

wxg4net
会员
注册时间: 2012-01-07
帖子: 274

局域网定时随机使用IP脚本

#!/usr/bin/bash
while true ; do
	ip=$(($RANDOM/220+2))
	ip_dst="192.168.0."$ip
	ping -c 1 $ip_dst > /dev/null
	if [ $? -gt 0 ]
	then
		break;
	fi
done

profile="/etc/netctl/here"
profile_temp="/tmp/here.profile"
profile_body=`cat /etc/netctl/examples/here`
echo "$profile_body" > $profile_temp
echo "Address='$ip_dst/24'" >> $profile_temp
if [ ! -L "$profile" ]; then
	ln -sf $profile_temp $profile
fi
exit 0

定时器

[android:/etc/systemd/system] cat ip.timer 
[Unit]
Description=Run Every 15min 

[Timer]
OnCalendar=*:0/15
 
[Install]
WantedBy=timers.target.wants
[android:/etc/systemd/system] cat ip.service 
[Unit]
Description=Automatic wireless network connection using here profiles

[Service]
ExecStartPre=-/usr/bin/here
ExecStart=/usr/bin/netctl restart here
Type=simple

[Install]
WantedBy=multi-user.target

最近编辑记录 wxg4net (2016-12-02 08:54:05)


Arch Linux User

离线

页脚