修改hosts的.bat代码

 
第一种:
echo off
chcp 65001

set sp0=------------------------
set sp1=host助手
set hostsfile="%SYSTEMROOT%\System32\Drivers\etc\hosts"
title %sp1%
color 5f

:mainmenu
echo %sp0%
echo %sp1%
echo %sp0%
echo 1.编辑hosts		2.恢复hosts
echo 3.打开hosts文件		4.退出
echo.

set input=
set /p input=请选择:
if "%input%" == "" goto :mainmenu
if "%input%" =="1" goto :writehost
if "%input%" =="2" goto :recovery
if "%input%" =="3" goto :showhosts
if "%input%" =="4" goto :endtime
echo.

:writehost
cls
echo %sp0%
echo %sp0%
echo 120.0.0.1 www.baidu.com >> "%hostsfile%"
echo 编写完毕
echo %sp0%
echo %sp0%
echo 任意键回到主界面
echo.
pause >nul
goto :mainmenu




:recovery
cls
echo %sp0%
echo %sp0%
echo # Copyright (c) 1993-2009 Microsoft Corp.>hosts
echo #>>hosts
echo # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.>>hosts
echo #>>hosts
echo # This file contains the mappings of IP addresses to host names. Each>>hosts
echo # entry should be kept on an individual line. The IP address should>>hosts
echo # be placed in the first column followed by the corresponding host name.>>hosts
echo # The IP address and the host name should be separated by at least one>>hosts
echo # space.>>hosts
echo #>>hosts
echo # Additionally, comments (such as these) may be inserted on individual>>hosts
echo # lines or following the machine name denoted by a '#' symbol.>>hosts
echo #>>hosts
echo # For example:>>hosts
echo #>>hosts
echo #      102.54.94.97     rhino.acme.com          # source server>>hosts
echo #       38.25.63.10     x.acme.com              # x client host>>hosts
echo.>>hosts
echo # localhost name resolution is handled within DNS itself.>>hosts
echo #    127.0.0.1       localhost>>hosts
echo #    ::1             localhost>>hosts
echo.>>hosts
copy hosts C:\Windows\System32\drivers\etc\
del hosts

echo hosts已恢复完毕
echo %sp0%
echo %sp0%
echo 任意键回到主界面
echo.
pause >nul
goto :mainmenu



:showhosts
cls
start "" notepad.exe %hostsfile%
echo 文件已打开
echo %sp0%
echo %sp0%
echo 任意键回到主界面
echo.
pause >nul
goto :mainmenu


:endtime
exit

 

 
 

第二种:通过文件内容复制来恢复修改的hosts

echo off
chcp 65001

set sp0=------------------------
set sp1=host助手
set hostsfile="%SYSTEMROOT%\System32\Drivers\etc\hosts"

title %sp1%
color 5f

:mainmenu
cls
echo %sp0%
echo %sp1%
echo %sp0%
echo 1.编辑hosts
echo 2.查看hosts
echo 3.退出
echo.

set input=
set /p input=请选择:
if "%input%" == "" goto :endtime
if "%input%" =="1" goto :writehost
if "%input%" =="2" goto :showhosts
if "%input%" =="3" goto :endtime
echo.

:writehost
copy %hostsfile% G:\back.txt
echo 备份完毕
echo %sp0%
echo 120.0.0.1 www.tutu.com >> "%hostsfile%"
echo %sp0%
echo 编写完毕,任意键恢复hosts
pause > nul
goto:back

:showhosts
start "" notepad.exe  %hostsfile%

:endtime
exit /B

:back
copy G:\back.txt %hostsfile% 
echo 编写完毕,任意键回到主菜单
pause > nul
goto:mainmenu

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值