可以把脚本放到自启动脚本目录下, 这样不用每次进行网页认证. 另外对于没有图形界面的纯字符终端也非常有用. 还有就是当chrome打开时, 如果没有认证, 则会把所有已保存的页面重定向到登录页面, 造成非常麻烦!
#!/bin/bash
declare -f showHelp
showHelp()
{
cat <<EOF
usage: $0 [-u username] [-p password] [-i ip] [-h]
EOF
exit 1
}
# 解析参数
while getopts ":u:p:i:h" arg
do
case $arg in
u)
user=$OPTARG
;;
p)
password=$OPTARG
;;
h)
showHelp
;;
i)
ip=$OPTARG
;;
:|?|*)
showHelp
;;
esac
done
# 如果没有获取参数,则交互式输入
if [ -z "$user" ]
then
read -p"username:" user
fi
if [ -z "$password" ]
then
stty -echo
read -p"password:" password
stty echo
echo
fi
# 检查参数是否成功输入
[ -z "$user" ] && showHelp
[ -z "$password" ] && showHelp
# 发送post数据, 注意这里没有保存cookies
ip=${ip:-"10.3.8.211"} # 这里设置认证ip的缺省值
curl -A "Mozilla/4.0(compatible;MSIE 6.0;Windows NT 5.0)" -d "username=$user&upass=$password&save_me=1&R1=0" "$ip" -o output.html 2>/dev/null
# 本来想用nc的,结果发现即使不登录也会返回0
# FIXME: 下面这段检测网络是否正确连接的代码,不健壮,不保证输出是正确结果, 运行后请手动ping
if ping -c 1 -w 2 baidu.com &>/dev/null
then
echo "The internet is Ok!"
else
echo "Fail to login!"
fi
2025年5月11日 02:17
Below you will understand what is important, the idea provides one of the links with an exciting site: Kissimmee Termite Control
2025年5月11日 02:17
I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. Orlando Exterminator
2025年5月11日 02:19
I like to recommend exclusively fine plus efficient information and facts, hence notice it: Bed Bug Treatment Oviedo
2025年7月19日 07:26
These websites are really needed, you can learn a lot. traffic and truck driving citation
2025年10月28日 19:36
In this case you will begin it is important, it again produces a web site a strong significant internet site: health and wellness retreats Mexico
2025年10月28日 19:36
I like to recommend exclusively fine plus efficient information and facts, hence notice it: Fertility Treatments Mexico
2025年10月28日 19:36
Why do only so much written on this subject? Here you see more. integrative wellness coach Vancouver women
2025年12月25日 22:01
정보가 명확하고 정확해 보입니다. 출장마사지