首页 » IT技术 » 脚本和标记 » 正文

批处理设置internet代理

最近总是要用到各种代理服务器,各种切换,麻烦的要死,索性写个bat快速处理下,代码如下:

[code]
@echo off
:main
color a
cls
echo *************************************************
echo 用于设置Internet代理:
echo 1、设置Internet代理为127.0.0.1:8087
echo 2、自定义代理地址及端口
echo 3、停止代理
echo 4、对以下列开头的地址不使用代理服务器
echo 5、对本地地址不使用代理服务器
echo 注意:本程序会关闭IE浏览器,请注意保存信息
echo 单独操作4,5是没有任何意义的。
echo by:frogchou@163.com
echo *************************************************
set /p select=请输入操作指令:
if %select% == 1 goto do1
if %select% == 2 goto do2
if %select% == 3 goto do3
if %select% == 4 goto do4
if %select% == 5 goto do5
if "%select%" == "q" (goto exit) else (goto selecterror)
:do1
rem 修改IE代理地址为:127.0.0.1,端口8087 goagent 默认设置
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
IF %ERRORLEVEL% GTR 0 goto error
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "127.0.0.1:8087" /f
IF %ERRORLEVEL% GTR 0 goto error
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "" /f
IF %ERRORLEVEL% GTR 0 (goto error) else (goto succ)
:do2
set /p ip=请输入代理IP地址:
set /p port=请输入代理IP端口:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
IF %ERRORLEVEL% GTR 0 goto error
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "%ip%:%port%" /f
IF %ERRORLEVEL% GTR 0 goto error
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "" /f
IF %ERRORLEVEL% GTR 0 (goto error) else (goto succ)
:do3
rem 去除代理
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
IF %ERRORLEVEL% GTR 0 goto error
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "" /f
IF %ERRORLEVEL% GTR 0 goto error
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d 0 /f
IF %ERRORLEVEL% GTR 0 (goto error) else (goto succ)
:do4
set /p ipundo=请输入不需要代理IP地址多个地址用英文;号隔开,例如192.168.*;172.*:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "%ipundo%" /f
IF %ERRORLEVEL% GTR 0 (goto error) else (goto succ)
:do5
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "<local>" /f
IF %ERRORLEVEL% GTR 0 (goto error) else (goto succ)
:error
color c
echo 失败!请看提示!按任意键返回主界面。。。& pause >nul
goto main
:selecterror
color c
echo 选择错误!!!!按任意键返回上一级 & pause > nul
goto main
:succ
rem 要重启资源管理器不然不生效
echo 正在重启资源管理器。。。。
taskkill /im iexplore.exe /f >nul
taskkill /im explorer.exe /f >nul
ping -n 4 127.0.0.1 > nul
start c:\windows\explorer.exe
echo 操作成功!按任意键返回主界面。。。& pause >nul
goto main
[/code]

结束了。

发表评论