054 批处理文件:Win7_网络连接辅助工具.bat

绿色单文件,方便Win7下清除DNS解析缓存、网页缓存、Cookies,修改DNS服务器,以及查看或清空hosts文件。
下载Win7_网络连接辅助工具.bat
百度网盘

截图(Win7_网络连接辅助工具.bat)


源代码:

::更新:http://dramatea.com/a/54
::作者:Dramatea
::本作品采用知识共享署名-非商业性使用-相同方式共享3.0 Unported 许可协议进行许可
::更多许可详情请查看 : http://creativecommons.org/licenses/by-nc-sa/3.0/
::------------------------------------------------------------------------------------
::Update: http://dramatea.com/a/54
::Author: Dramatea
::This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
::View more : http://creativecommons.org/licenses/by-nc-sa/3.0/
::------------------------------------------------------------------------------------
::------------------------------------------------------------------------------------
@echo off
mode con cols=70 lines=35
title =Win7 网络连接辅助工具 by Dramatea
color 2f
set fgx=----------------------------------------------------------------------
cls
call :about
echo.
echo %fgx%
echo 提示:此 bat 工具需要以管理员权限运行(在此 bat 文件上右击选择“以管理员身份运行”)
echo.
goto cmdfinish
:cmdlist
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo ++++++++++++++++++++++++++++++++主菜单++++++++++++++++++++++++++++++++
echo 1 清除之
echo [11] 清除 DNS 解析缓存
echo [12] 清理网页缓存
echo [13] 清理 Cookies
echo.
echo 2 设置 DNS 服务器( IPv4 )
echo [20] 查看当前 DNS 设置
echo [21] 修改为自动获取( DHCP )
echo [22] 修改为谷歌公共 DNS ( 8.8.8.8、8.8.8.4 )
echo [23] 修改为香港某公共 DNS (202.181.202.140、202.181.224.2 )
echo [24] 修改为 Norton DNS ( 198.153.192.1、198.153.194.1 )
echo [25] 修改为 OpenDNS ( 208.67.222.222、208.67.220.220 )
echo.
echo 3 hosts
echo [30] 查看当前 hosts 文件
echo [31] 打开 hosts 文件所在目录
echo [32] 替换 hosts 文件 (用于替换的文件:hosts.txt)
echo [33] 清空 hosts 文件
echo.
echo [9] 关于
echo [0] 退出
echo.
set /a choice= 9999
set /p choice=请选择功能(输入序号):
echo %fgx%
if %choice%==0 exit
if %choice%==11 call :cmd11 & goto cmdfinish
if %choice%==12 call :cmd12 & goto cmdfinish
if %choice%==13 call :cmd13 & goto cmdfinish
if %choice%==20 call :cmd20 & goto cmdfinish
if %choice%==21 call :cmd21 & goto cmdfinish
if %choice%==22 call :cmd22 & goto cmdfinish
if %choice%==23 call :cmd23 & goto cmdfinish
if %choice%==24 call :cmd24 & goto cmdfinish
if %choice%==25 call :cmd25 & goto cmdfinish
if %choice%==30 call :cmd30 & goto cmdfinish
if %choice%==31 call :cmd31 & goto cmdfinish
if %choice%==32 call :cmd32 & goto cmdfinish
if %choice%==33 call :cmd33 & goto cmdfinish
if %choice%==9 call :about & goto cmdfinish
goto cmdlist
:cmdfinish
echo %fgx%
pause
goto cmdlist

:cmd11
ipconfig /flushdns
echo 清除 DNS 解析缓存结束
goto :eof
exit

:cmd12
echo 清除网页缓存提示:
echo 若已长期未清理,本次清理可能会花费较多时间。
echo 清理过程中可以按 [Ctrl] + [C] 键强制终止。
echo %fgx%
pause
echo 开始清除网页缓存...
del /s /q "%localappdata%\\Microsoft\Windows\\Temporary Internet Files\\*.*"
echo 清除网页缓存结束
goto :eof
exit

:cmd13
echo 清除 Cookies...
del /s /q "%userprofile%\\Cookies\\*.*"
del /s /q "%localappdata%\\Temp\\Cookies\\*.*"
del /s /q "%appdata%\\Microsoft\\Windows\\Cookies\\*.*"
echo 清除 Cookies 结束
goto :eof
exit

:cmd2_choice_netid
echo 载入本机网络连接列表....
netsh interface ip show interface
echo %fgx%
set /a choice_netid=9999
set /p choice_netid=请选择网络连接(输入所对应的Idx):
echo %fgx%
if %choice_netid%==9999 goto cmd2_end
goto :eof
:cmd2_end
echo 未选择网络连接,直接返回主菜单
echo %fgx%
goto cmdlist
exit

:cmd20
echo 设置 DNS 服务器——查看当前 DNS 设置
call :cmd2_choice_netid
netsh interface ip show dns name=%choice_netid%
goto :eof
exit

:cmd21
echo 设置 DNS 服务器——修改为自动获取( DHCP )
call :cmd2_choice_netid
echo -----当前配置:
netsh interface ip show dns name=%choice_netid%
echo -----修改为自动获取( DHCP )...
netsh interface ip set dns name=%choice_netid% dhcp
echo -----修改后配置:
netsh interface ip show dns name=%choice_netid%
echo 设置 DNS 服务器结束
goto :eof
exit

:cmd22
echo 设置 DNS 服务器——修改为谷歌公共 DNS ( 8.8.8.8,8.8.8.4 )
call :cmd2_choice_netid
echo -----当前配置:
netsh interface ip show dns name=%choice_netid%
echo -----修改为谷歌公共 DNS ( 8.8.8.8,8.8.8.4 )...
netsh interface ip set dns name=%choice_netid% static 8.8.8.8 both
netsh interface ip add dns name=%choice_netid% 8.8.8.4 index=2
echo -----修改后配置:
netsh interface ip show dns name=%choice_netid%
echo 设置 DNS 服务器结束
goto :eof
exit

:cmd23
echo 设置 DNS 服务器——修改为香港某公共 DNS ( 202.181.202.140, 202.181.224.2 )
call :cmd2_choice_netid
echo -----当前配置:
netsh interface ip show dns name=%choice_netid%
echo -----修改为香港某公共 DNS ( 202.181.202.140, 202.181.224.2 )...
netsh interface ip set dns name=%choice_netid% static 202.181.202.140 both
netsh interface ip add dns name=%choice_netid% 202.181.224.2 index=2
echo -----修改后配置:
netsh interface ip show dns name=%choice_netid%
echo 设置 DNS 服务器结束
goto :eof
exit

:cmd24
echo 设置DNS服务器——修改为 Norton DNS ( 198.153.192.1、198.153.194.1 )
call :cmd2_choice_netid
echo -----当前配置:
netsh interface ip show dns name=%choice_netid%
echo -----修改为 Norton DNS ( 198.153.192.1, 198.153.194.1 )...
netsh interface ip set dns name=%choice_netid% static 198.153.192.1 both
netsh interface ip add dns name=%choice_netid% 198.153.194.1 index=2
echo -----修改后配置:
netsh interface ip show dns name=%choice_netid%
echo 设置 DNS 服务器结束
goto :eof
exit

:cmd25
echo 设置 DNS 服务器——修改为 OpenDNS ( 208.67.222.222、208.67.220.220 )
call :cmd2_choice_netid
echo -----当前配置:
netsh interface ip show dns name=%choice_netid%
echo -----修改为 OpenDNS ( 208.67.222.222, 208.67.220.220 )...
netsh interface ip set dns name=%choice_netid% static 208.67.222.222 both
netsh interface ip add dns name=%choice_netid% 208.67.220.220 index=2
echo -----修改后配置:
netsh interface ip show dns name=%choice_netid%
echo 设置 DNS 服务器结束
goto :eof
exit

:cmd30
echo hosts——查看当前 hosts 文件
start notepad.exe %windir%\\system32\\drivers\\etc\\hosts
echo 已启动记事本程序载入 hosts 文件
goto :eof
exit

:cmd31
echo hosts——打开 hosts 文件所在目录
start %windir%\\system32\\drivers\\etc
echo 已打开目录:%windir%\system32\drivers\etc
goto :eof
exit

:cmd32
echo hosts——替换 hosts 文件 (请确保本工具所在目录内有用于替换的文件:hosts.txt)
pause
copy /y hosts.txt %windir%\\system32\\drivers\\etc\hosts
goto :eof
exit

:cmd33
echo hosts——清空 hosts 文件
echo ---生成空 hosts 文件...
echo # WinNetTool has Re-Wrote this hosts file>emptyhosts
echo # ------------------------------------------------>>emptyhosts
echo # IP Hosts>>emptyhosts
echo # 127.0.0.1 localhost>>emptyhosts
echo ---替换当前 hosts 文件为空文件...
copy /y emptyhosts %windir%\\system32\\drivers\\etc\hosts
del emptyhosts>nul
echo.
echo 清空 hosts 文件结束(清空成功的标志是复制成功1个文件,否则为清空失败)
goto :eof
exit

:about
echo.
echo ┏━━━━━━━━━━ Win7 网络连接辅助工具 ━━━━━━━━━━┓
echo ┃ ┃
echo ┃ * 适用于 Windows 7 ┃
echo ┃ * 更新于 2013/01/15 ┃
echo ┃ http://dramatea.com/a/54 ┃
echo ┃ * 作者:Dramatea ┃
echo ┃ ┃
echo ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
echo [ CC BY-NC-SA 3.0 ]
echo.
goto :eof
exit

exit