原来如此

一个获取代理的脚本

fog posted @ 2008年8月25日 16:42 in 生活相关 with tags linux life , 297 阅读
IBM X60在ubuntu下使用投影仪

曾经在linuxsir.org上看到过一个获取代理的脚本,觉得挺实用的,于是拿来自己改了改,效果还不错,贴出来分享。

#
# This script is used to get free http proxies from
# www.cybersyndrome.net
#
# fog, Sun Jul 23 00:17:54 2006
#

#!/bin/bash

red="\033[31m"
green="\033[32m"
yellow="\033[33m"
end="\033[0m"

test_page="www.google.cn"
timeout=20

if [ "$#" = 0 ]
then
    echo -e ${yellow}Using "$test_page" to test ...${end}
    echo
else
    timeout=$1
    if [ "$#" = 2 ]
    then
        test_page=$2
    fi
fi

proxy_page="http://www.cybersyndrome.net/pla4.html"
echo -n -e ${yellow}"Getting latest proxy file and abstract proxy ..."${end}
PROXYS=`wget --quiet -T 20 -t 1 -O - $proxy_page |grep '<li>'|sed -e 's/<[^<>]\{1,\}class=\"[^BCA]\">[^<>]\{1,\}<\/a>//g'|sed -e 's/<[^<>]\{1,\}>/ /g'`

if [ "$?" = 0 ]
then
    echo -e ${green}OK${end}
else
    echo -e ${red}Failed${end}
    exit 1
fi


WGET="wget --quiet --cache=off -T $timeout -t 1 -w 0 -O /dev/null $test_page"
PROXY=""

for proxy in $PROXYS ; do
    export http_proxy="http://$proxy"
#    echo "$http_proxy"
    /usr/bin/time -o /tmp/proxytimer_$proxy.txt -f %e $WGET &
done

echo Wait $timeout+2 seconds...
sleep $timeout
sleep 2

for proxy in $PROXYS;do
#    echo "$proxy"
    grep -q "status" /tmp/proxytimer_$proxy.txt || cat /tmp/proxytimer_$proxy.txt | sed -e "s/$/, $proxy/" >> /tmp/proxytimer_total
#    M=`grep -q "status" /tmp/proxytimer_$proxy.txt || cat /tmp/proxytimer_$proxy.txt | sed -e "s/$/, $proxy/" `
#    echo "<$M>"
#    echo $M >> /tmp/proxytimer_total
done

echo -e ${yellow}"Top 10 proxies in this run:"${end}
cat /tmp/proxytimer_total |grep -e "^[0-9]" |sort -n -t',' -k1| head -n10
rm -f /tmp/proxytimer_*


* 登录
*

simple_captcha.jpg
(输入验证码)