linux使用curl代理和检查及代理脚本sh

curl 检测代理
curl https://byy3.com -m 10 -o out.html --socks4 91.99.99.11:1080
说明:
curl shell 抓取网页命令
-m 10 连接超时时间,最大为10秒
-o out.html 抓取网页输出到 out.html
--socks4 91.99.99.11:1080 代理协议采用 --socks4
此外,curl 7.21.7版本以上,还支持代理协议格式如下:
curl https://byy3.com -m 10 -o out.html -x socks4://91.99.99.11:1080
或
curl https://byy3.com -m 10 -o out.html --proxy socks4://91.99.99.11:1080
更多请详见米扑代理的代码示例:
https://proxy.mimvp.com/demo.php (Shell curl wget)
下面是验证脚本代码proxy.sh添加权限chmod +x proxy.sh
#!/bin/bash# sudo apt-get install autossh# byy3.com at 2021-02-09# remote host and portREMOTE_HOST=mimvp@115.29.237.28REMOTE_PORT=22# proxy ip addrIP='91.99.99.11'# proxy portPORT=1080# proxy spider urlCHECK_URL='http://www.baidu.com'AUTOSSH_MONITOR_PORT=20000LOG='check_proxy.log'function __help(){ echo 'usage: proxy [run | show | check | log]example: proxy run # run proxy proxy show # show proxy information proxy check # check proxy status proxy log # show proxy log'}function __show(){ OUTPUT=`ps -ef | grep -v "grep" | grep "autossh"` if [[ -n $OUTPUT ]]; then echo $OUTPUT else echo 'Proxy not working' fi}# options for autossh:# -M specifies the base monitoring port to use.# -f run in background (autossh handles this, and does not pass it to ssh.)## options for ssh:# -q Quiet mode.# -T Disable pseudo-tty allocation.# -f Requests ssh to go to background just before command execution.# -n Redirects stdin from /dev/null (actually, prevents reading from stdin). This must be used when ssh is run in the background.# -N Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only).# -g Allows remote hosts to connect to local forwarded ports.# -D port Specifies a local dynamic application-level port forwarding.function __start(){ echo 'try to connect remote host...' echo "autossh -M $AUTOSSH_MONITOR_PORT -f -qTnNg -D $REMOTE_PORT $REMOTE_HOST" autossh -M $AUTOSSH_MONITOR_PORT -f -qTnNg -D $REMOTE_PORT $REMOTE_HOST __show}function __check(){ cmd_4="curl $CHECK_URL -m 10 --socks4 $IP:$PORT" cmd_5="curl $CHECK_URL -m 10 --socks5 $IP:$PORT" echo "cmd_4 : $cmd_4" echo "try to connect proxy $IP:$PORT" dtime=$(date +'%Y-%m-%d__%H:%M:%S') echo $dtime RESPONSE=`$cmd_4` echo "RESPONSE: $RESPONSE" if [[ -n $RESPONSE ]]; then echo $RESPONSE echo 'Proxy is working...' echo "$dtime -- Proxy is working" >> $LOG else echo 'Proxy not working...' echo "$dtime -- Proxy not working" >> $LOG fi}if [[ $# -eq 0 ]]; then __helpelse action=$1 case $action in 'run') __start ;; 'show') __show ;; 'check') __check ;; 'log') tail -n 10 $log ;; *) __help ;; esacfi
admin