公司产品部测试产品需要经常修改Hosts,很多新人不会,写了个批处理,保存为bat格式,或者编译成exe格式,运行即可。代码如下:
@echo off color 0A echo 说明: echo. echo 请退出360和其他安全类软件!!!之后进行下一步操作。 echo. echo 备份当前Hosts文件到您选择的分区的《Hosts文件备份》文件夹当前《日期时间》文件夹里,或还原Hosts文件为初始状态。 echo. echo. :menu echo 1.备份当前Hosts文件 echo 2.还原Hosts文件为初始状态 echo 3.退出程序 echo. echo 请选择您要进行的操作: :input set /p PD= if "%PD%"=="1" goto backup if "%PD%"=="2" goto recovery if "%PD%"=="3" goto quit echo 输入错误,请重新输入 goto input :backup echo 请输入您要保存的分区盘符,例如:D set /p desk= set T=%date:~,4%-%date:~5,2%-%date:~8,2%-%time:~0,2%-%time:~3,2%-%time:~6,2% md %desk%:\Hosts文件备份\%T%copy C:\Windows\System32\drivers\etc\hosts %desk%:\Hosts文件备份\%T%echo Hosts文件已经备份到《%desk%:\Hosts文件备份\%T%\》目录中 start %desk%:\Hosts文件备份\%T% :Recovery 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\etcdel hosts exit :quit exit
时间: 2024-10-17 13:34:15