手机
当前位置:查字典教程网 >脚本专栏 >DOS/BAT >用批处理修改host文件的代码
用批处理修改host文件的代码
摘要:@echo127.0.0.1baidu.com>>C:WindowsSystem32Driversetchosts这样就是换一行写入。如果还...

@echo 127.0.0.1 baidu.com >>C:WindowsSystem32Driversetchosts

这样就是换一行写入。

如果还想换一行,就写:

复制代码 代码如下:

@echo. >>C:WindowsSystem32Driversetchosts

@echo 127.0.0.1 baidu.com >>C:WindowsSystem32Driversetchosts

@echo 192.168.4.201 ibmrac1 >>C:WindowsSystem32Driversetchosts

@echo 192.168.4.202 ibmrac2 >>C:WindowsSystem32Driversetchosts

@echo 192.168.4.203 vip-ibmrac1 >>C:WindowsSystem32Driversetchosts

@echo 192.168.4.204 vip-ibmrac2>>C:WindowsSystem32Driversetchosts

@echo 172.16.1.53 ssosvr>>C:WindowsSystem32Driversetchosts

复制代码 代码如下:

@echo off

set stHosts=172.16.1.53 ssosvr

FOR /F "eol=# tokens=1 delims=" %%i in (%systemroot%system32driversetchosts) do if "%stHosts%"=="%%i" exit

echo %stHosts%>> %systemroot%system32driversetchosts

由于测试需要经常修改本机host,可以用脚本修改:

分别做两个批处理,一个内网,一个外网,用的时候切换运行即可

如内网.bat

复制代码 代码如下:

cd /d %windir%system32driversetc

del hosts.bak //删除原来备份文件

ren hosts hosts.bak //备份现在host

for /f "eol=# tokens=1,2" %%i in (hosts.bak) do call :checkvalue %%i %%j

goto end

:checkvalue

echo %2 | find /i "szshequ.com" //寻找制定记录删除

if %errorlevel%==1 (echo %1 %2 >>hosts)

:end

type C:WINDOWSsystem32driversetchosts

type C:WINDOWSsystem32driversetchosts | find "szshequ.com" && goto yes

::echo 192.168.2.188 szshequ.com >> ""

echo 192.168.2.188 szshequ.com >> C:WINDOWSsystem32driversetchosts

echo 192.168.2.188 www.szshequ.com >> C:WINDOWSsystem32driversetchosts

echo 192.168.2.188 bbs.szshequ.com >> C:WINDOWSsystem32driversetchosts

echo 192.168.2.188 cost.szshequ.com >> C:WINDOWSsystem32driversetchosts

echo 192.168.2.188 pp.szshequ.com >> C:WINDOWSsystem32driversetchosts

echo 192.168.2.188 yh.szshequ.com >> C:WINDOWSsystem32driversetchosts

echo 192.168.2.188 club.szshequ.com >> C:WINDOWSsystem32driversetchosts

echo 192.168.2.188 shop.szshequ.com >> C:WINDOWSsystem32driversetchosts

echo 192.168.2.188 images.szshequ.com >> C:WINDOWSsystem32driversetchosts

echo 192.168.2.188 files.szshequ.com >> C:WINDOWSsystem32driversetchosts

echo 192.168.2.188 ajax.szshequ.com >> C:WINDOWSsystem32driversetchosts

【用批处理修改host文件的代码】相关文章:

批处理实例代码教程 集合

使用批处理禁用(启用)组策略的代码

批处理实现一行内容分行输出的代码

在批处理文件或配置文件中加入注释

批处理 删除重复行的代码

批处理提取不同行上的内容的代码

酷狗去广告一键去除批处理代码

批处理版的SC

批处理删除空文件夹

批处理实现文本内容横列变纵列的代码

精品推荐
分类导航