|
weasel
初级用户
 
积分 118
发帖 66
注册 2006-8-18
状态 离线
|
『楼 主』:
关于字符串提取&替换学习-建立适合自己的pac脚本
我们访问一些站点的时候需要使用代理服务器才可以访问,但是频繁的切换代理地址却是件很麻烦的事情,利用配置自动代理脚本,就可以不需要每次都去切换了。
使用代理脚本的好处是:
一:代理脚本文件 My.pac几乎支持市面上流行的所有浏览器,如IE、Opera、chrome、Firefox等。
二:支持安装任意一个代理(比如:Tor、GAppProxy、ssh……)
三:本工具产生的代理脚本是依托gfwlist产生的,gfwlist是AutoProxy的代理列表,并油http://autoproxy.org/zh-CN进行列表维护和更新,它可以协助您更好地使用您的代理。
四:本工具产生的代理脚使用脚本屏蔽网页广告这是脚本的一段特色功能,这个东西的好处是简单,功能强大,可配置性强,使用的黑洞代理技术,不去下载广告内容,绝对的no-casting ad block。
原文地址:http://linux.jgxx.com/cgi-wsq/wsqbbs/wsqbbs.pl?cx=3&hf=1&hfbm=81271521114V926 cls&@echo off&color 2f&cd /d %~dp0
:::设置My.Pac存放路径路径
Set My_PacPath=d:\my.pac
echo.&echo 正在查找设并置代理端口…………
for /f %%a in ('tasklist ^|find /i "proxy.exe"') do Set Port=PROXY 127.0.0.1:8000&echo.&echo 当前代理端口:127.0.0.1:8000&goto :开始
for /f %%a in ('tasklist ^|find /i "polipo.exe"') do Set Port=PROXY 127.0.0.1:8118&echo.&echo 当前代理端口:127.0.0.1:8118&goto :开始
for /f %%a in ('tasklist ^|find /i "privoxy.exe"') do Set Port=PROXY 127.0.0.1:8118&echo.&echo 当前代理端口:127.0.0.1:8118&goto :开始
for /f %%a in ('tasklist ^|find /i "AdvTor.exe"') do Set Port=PROXY 127.0.0.1:9050&echo.&echo 当前代理端口:127.0.0.1:9050&goto :开始
for /f %%a in ('tasklist ^|find /i "Tor.exe"') do Set Port=SOCKS 127.0.0.1:9050&echo.&echo 当前代理端口:SOCKS 127.0.0.1:9050&goto :开始
echo.&echo 没有找到你的代理端口,请先运行代理软件!,请按任意键退出! &pause>nul&exit
:开始
echo.&pause
echo.&echo 正在下载(AutoProxy gfwList)文件………… &echo ==============================================================================
Set My_Path=gfwlist.txt&Set My_Proxy=http://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt
curl "%My_Proxy%">%My_Path%_tmp.txt
:::curl -x 127.0.0.1:8000 "%My_Proxy%">%My_Path%_tmp.txt
Base64.exe -d %My_Path%_tmp.txt %My_Path%&echo ==============================================================================
echo.&echo 正在去掉不包含点的行…………&Call ::去掉不包含点的行
for %%a in (! [ ^( baidu wikipedia google) do Call :去掉包含指定字符串的行 %%a
for %%a in (a b https:// http:// http: www) do Call :替换字符串 %%a
echo.&echo 正在去掉行头、尾特殊符号…………&Call :去掉行头尾特殊符号
echo.&echo 正在删除重复行…………&Call :删除重复行
echo.&echo 正在去掉不包含点的行…………&Call :去掉不包含点的行
echo.&echo 正在写入代理脚本(%My_PacPath%)文件…………
>%My_PacPath% Echo function FindProxyForURL(url, host){
>>%My_PacPath% Echo var ProxyPort="%Port%";//根据你的代理软件修改代理地址和端口
>>%My_PacPath% Echo var patterns = new Array(
for /f "skip=88 delims=" %%a in (%~0) do echo "%%a",>>%My_PacPath%
for /f %%i in (%My_Path%) do echo "%%i",>>%My_PacPath%
>>%My_PacPath% Echo "a.cc");
>>%My_PacPath% Echo for (i in patterns) {
>>%My_PacPath% Echo if(shExpMatch(url.toLowerCase(),"*" + patterns[i].toLowerCase() + "*")){return ProxyPort;};
>>%My_PacPath% Echo };
>>%My_PacPath% Echo return "DIRECT";
>>%My_PacPath% Echo };
echo.&&echo [ %My_PacPath% ]代理脚创建本完成,请按任意键退出!&&pause>nul&exit
:去掉包含指定字符串的行
echo.&echo 正在删除包含 %1 字符串的行(不用代理的站点)…………
TYPE %My_Path%|FIND /I /V "%1">%My_Path%_tmp.txt
move %My_Path%_tmp.txt %My_Path%>nul
goto :eof
:去掉不包含点的行
TYPE %My_Path%|FIND ".">%My_Path%_tmp.txt
move %My_Path%_tmp.txt %My_Path%>nul
goto :eof
:替换字符串
setlocal enabledelayedexpansion
set replaced=%1
if /i "%1"=="a" set replaced=^|
if /i "%1"=="b" set replaced=^@
set all=
echo.&echo 正在替换 ^%replaced% 字符串…………
for /f "delims=" %%i in ('type "%My_Path%"') do (
set str=%%i
set "str=!str:%replaced%=%all%!"
echo !str!>>%My_Path%_tmp.txt
)
move "%My_Path%_tmp.txt" "%My_Path%" >nul
goto :eof
:删除重复行
sort %My_Path%>%My_Path%_tmp.txt
echo.>%My_Path%
for /f "delims=" %%i in (%My_Path%_tmp.txt) do (if not defined %%i set %%i=A & echo %%i>>%My_Path%)
del %My_Path%_tmp.txt >nul
goto :eof
:去掉行头尾特殊符号
setlocal enabledelayedexpansion
for /f %%i in ('type "%My_Path%"') do (
SET str=%%i
if "!str:~0,1!"=="*" set "str=!str:~1!"
if "!str:~0,1!"=="." set "str=!str:~1!"
if "!str:~0,1!"=="/" set "str=!str:~1!"
if "!str:~-1!"=="*" set "str=!str:~0,-1!"
if "!str:~-1!"=="/" set "str=!str:~0,-1!"
echo !str!>>%My_Path%_tmp.txt
)
move %My_Path%_tmp.txt "%My_Path%" >nul
goto :eof
==========请在下面输入要添加代理的url的关键字=========
[ Last edited by weasel on 2010-4-18 at 00:59 ]
|
|
2010-4-16 16:54 |
|
|
weasel
初级用户
 
积分 118
发帖 66
注册 2006-8-18
状态 离线
|
『第
2 楼』:
重新改了下: cls&@echo off&color 2f&cd /d %~dp0
:::设置My.Pac存放路径路径
Set My_PacPath=d:\my.pac
Set AdPort=PROXY 255.255.255.0:3421
echo.&echo 正在查找设并置代理端口…………
for /f %%a in ('tasklist ^|findstr /i "proxy.exe"') do Set Port=PROXY 127.0.0.1:8000&echo.&echo 当前代理端口:127.0.0.1:8000&goto :开始
for /f %%a in ('tasklist ^|findstr /i "polipo.exe"') do Set Port=PROXY 127.0.0.1:8118&echo.&echo 当前代理端口:127.0.0.1:8118&goto :开始
for /f %%a in ('tasklist ^|findstr /i "privoxy.exe"') do Set Port=PROXY 127.0.0.1:8118&echo.&echo 当前代理端口:127.0.0.1:8118&goto :开始
for /f %%a in ('tasklist ^|findstr /i "AdvTor.exe"') do Set Port=PROXY 127.0.0.1:9050&echo.&echo 当前代理端口:127.0.0.1:9050&goto :开始
for /f %%a in ('tasklist ^|findstr /i "Tor.exe"') do Set Port=SOCKS 127.0.0.1:9050&echo.&echo 当前代理端口:SOCKS 127.0.0.1:9050&goto :开始
Set Port=DIRECT
echo.&echo 没有找到你的代理端口!请先运行代理软件或自行修改my.pac文件里的代理端口。&pause
:开始
echo.&echo 正在下载(AutoProxy gfwList)文件…………
echo ==============================================================================
Set My_Path=gfwlist.txt&Set My_Proxy=http://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt
If Exist "curl.exe" curl.exe "%My_Proxy%">%My_Path%_tmp.txt
If not Exist "curl.exe" Call :NewDete "%My_Proxy%" %My_Path%_tmp.txt
If not Exist "%My_Path%_tmp.txt" echo.&echo 没有下载完成………… &pause
If Exist "%My_Path%_tmp.txt" echo.&echo 下载完成………… &Call :Base64&Base64.exe -d %My_Path%_tmp.txt %My_Path%&del Base64.exe >nul
If Exist "My_Proxy.txt" (for /f "skip=1 delims=" %%a in (My_Proxy.txt) do echo %%a>>%My_Path%)
echo ==============================================================================
for %%a in (! [ ^( baidu) do Call :去掉包含指定字符串的行 %%a %My_Path%
for %%a in (a b) do Call :替换字符串 %%a %My_Path%
echo.&echo 正在去掉行头、尾特殊符号………… &Call :去掉行头尾特殊符号 %My_Path%
echo.&echo 正在删除重复行…………&Call :删除重复行 %My_Path%
for %%a in (mp mail www cn https://www.google.com https://chrome.google.com) do Call :去掉完全匹配的行 %%a %My_Path%
echo.&echo 正在写入代理脚本(%My_PacPath%)文件…………
>%My_PacPath% Echo function FindProxyForURL(url, host){
>>%My_PacPath% Echo var ProxyPort="%Port%";//根据你的代理软件修改代理地址和端口,将引号内的内容改为你的代理软件的ip:端口
>>%My_PacPath% Echo var Blackhole="%AdPort%";
>>%My_PacPath% Echo if (typeof(navigator) != 'undefined'
>>%My_PacPath% Echo ^&^& navigator.appVersion.indexOf("Mac") != -1) {
>>%My_PacPath% Echo Blackhole = "PROXY 0.0.0.0:3421";}
>>%My_PacPath% Echo if(/[/]([^^/]*?)(advert^|adverts?^|adimage^|adinfo^|adframe^|adserver^|admentor^|adview^|banner^|bannerimg^|popup^|popunder^|alimama^|popad^|special)(s)?[_.\/]/i.test(url)) return Blackhole;
>>%My_PacPath% Echo var adblocklist = new Array(
>>%My_PacPath% Echo ".ad.",
>>%My_PacPath% Echo "/ad.",
>>%My_PacPath% Echo ".ad-",
>>%My_PacPath% Echo ".ad?.",
>>%My_PacPath% Echo "/ad?.",
>>%My_PacPath% Echo "/ad/",
>>%My_PacPath% Echo "/ads/",
>>%My_PacPath% Echo "/gg/",
>>%My_PacPath% Echo "/gg.",
>>%My_PacPath% Echo "/gg?.",
>>%My_PacPath% Echo ".gg?.",
>>%My_PacPath% Echo ".gg.",
>>%My_PacPath% Echo "/cpro/",
If Exist "My_AdBlock.txt" (for /f "skip=1 delims=" %%a in (My_AdBlock.txt) do echo "%%a",>>%My_PacPath%)
>>%My_PacPath% Echo "_ad_");
>>%My_PacPath% Echo var patterns = new Array(
for /f %%i in (%My_Path%) do echo "%%i",>>%My_PacPath%
>>%My_PacPath% Echo "a.cc");
>>%My_PacPath% Echo for (i in adblocklist) {
>>%My_PacPath% Echo if(shExpMatch(url.toLowerCase(),"*" + adblocklist[i].toLowerCase() + "*")){return Blackhole;};
>>%My_PacPath% Echo };
>>%My_PacPath% Echo for (i in patterns) {
>>%My_PacPath% Echo if(shExpMatch(url.toLowerCase(),"*" + patterns[i].toLowerCase() + "*")){return ProxyPort;};
>>%My_PacPath% Echo };
>>%My_PacPath% Echo return "DIRECT";
>>%My_PacPath% Echo };
del %My_Path% >nul&echo.&&echo [ %My_PacPath% ]代理脚创建本完成,请按任意键退出!&&pause>nul&exit
:去掉完全匹配的行
echo.&echo 正在删除完全匹配 %1 的行…………
type %2|findstr /b /e /v "%1" >%2_tmp.txt
move %2_tmp.txt %2>nul
goto :eof
:去掉包含指定字符串的行
echo.&echo 正在删除包含 %1 字符串的行(不用代理的站点)…………
TYPE %2|findstr /I /V "%1">%2_tmp.txt
move %2_tmp.txt %2>nul
goto :eof
:替换字符串
setlocal enabledelayedexpansion
set replaced=%1
if /i "%1"=="a" set replaced=^|
if /i "%1"=="b" set replaced=^@
set all=
echo.&echo 正在替换 ^%replaced% 字符串…………
for /f "delims=" %%i in ('type "%2"') do (
set str=%%i
set "str=!str:%replaced%=%all%!"
echo !str!>>%2_tmp.txt
)
move "%2_tmp.txt" "%2" >nul
goto :eof
:删除重复行
sort %1>%1_tmp.txt
echo.>%1
for /f "delims=" %%i in (%1_tmp.txt) do (if not defined %%i set %%i=A & echo %%i>>%1)
del %1_tmp.txt >nul
goto :eof
:去掉行头尾特殊符号
setlocal enabledelayedexpansion
for /f %%i in ('type "%1"') do (
SET str=%%i
if "!str:~0,1!"=="*" set "str=!str:~1!"
if "!str:~0,1!"=="." set "str=!str:~1!"
if "!str:~0,1!"=="/" set "str=!str:~1!"
if "!str:~-1!"=="*" set "str=!str:~0,-1!"
if "!str:~-1!"=="/" set "str=!str:~0,-1!"
echo !str!>>%1_tmp.txt
)
move %1_tmp.txt "%1" >nul
goto :eof
:NewDete
>"get.vbs" echo Set x= createObject("Microsoft.XML" ^& wsq ^& "HTTP"):x.Open "GET",LCase(WScript.Arguments(0)),0:x.Send():Set s = createObject("ADODB.Stream"):s.Mode = 3:s.Type = 1:s.Open():s.Write(x.responseBody):s.SaveToFile LCase(WScript.Arguments(1)),2
cscript.exe //nologo "get.vbs" %1 %2&del "get.vbs">nul
goto :eof
:Base64
goto :eof
[ Last edited by weasel on 2010-4-19 at 14:30 ]
附件
1: 瓦斯曲_代理脚本制作工具.rar (2010-4-19 14:27, 20.21 KiB,下载次数: 15)
|
|
2010-4-18 00:56 |
|
|