Get the App
SLTechnology News&Howtos  ›  Development  › 

How to modify host files with batch processing

Shulou Source: shulou.com Published: 2022-06-03 08:19:35 10月05日 Update

This article mainly introduces how to use batch processing to modify host files, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand it.

@ echo 127.0.0.1 baidu.com > C:\ Windows\ System32\ Drivers\ etc\ hosts

This is a new line of writing.

If you want to change the line, write:

The code is as follows:

@ echo. > > C:\ Windows\ System32\ Drivers\ etc\ hosts

@ echo 127.0.0.1 baidu.com > C:\ Windows\ System32\ Drivers\ etc\ hosts

@ echo 192.168.4.201 ibmrac1 > > C:\ Windows\ System32\ Drivers\ etc\ hosts

@ echo 192.168.4.202 ibmrac2 > > C:\ Windows\ System32\ Drivers\ etc\ hosts

@ echo 192.168.4.203 vip-ibmrac1 > > C:\ Windows\ System32\ Drivers\ etc\ hosts

@ echo 192.168.4.204 vip-ibmrac2 > > C:\ Windows\ System32\ Drivers\ etc\ hosts

@ echo 172.16.1.53 ssosvr > C:\ Windows\ System32\ Drivers\ etc\ hosts

The code is as follows:

@ echo off

Set stHosts=172.16.1.53 ssosvr

FOR / F "eol=# tokens=1 delims="% I in (% systemroot%\ system32\ drivers\ etc\ hosts) do if "% stHosts%" = = "% I" exit

Echo% stHosts% >% systemroot%\ system32\ drivers\ etc\ hosts

Since testing requires frequent changes to the native host, you can modify it with a script:

Do two batches respectively, one internal network and one external network, and you can switch and run when you use it.

Such as intranet .bat

The code is as follows:

Cd / d% windir%\ system32\ drivers\ etc

Del hosts.bak / / Delete the original backup file

Ren hosts hosts.bak / / backup now 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" / / looking for a set record to delete

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

: end

Type C:\ WINDOWS\ system32\ drivers\ etc\ hosts

Type C:\ WINDOWS\ system32\ drivers\ etc\ hosts | find "szshequ.com" & & goto yes

:: echo 192.168.2.188 szshequ.com > > "

Echo 192.168.2.188 szshequ.com > C:\ WINDOWS\ system32\ drivers\ etc\ hosts

Echo 192.168.2.188 www.szshequ.com > C:\ WINDOWS\ system32\ drivers\ etc\ hosts

Echo 192.168.2.188 bbs.szshequ.com > C:\ WINDOWS\ system32\ drivers\ etc\ hosts

Echo 192.168.2.188 cost.szshequ.com > C:\ WINDOWS\ system32\ drivers\ etc\ hosts

Echo 192.168.2.188 pp.szshequ.com > C:\ WINDOWS\ system32\ drivers\ etc\ hosts

Echo 192.168.2.188 yh.szshequ.com > C:\ WINDOWS\ system32\ drivers\ etc\ hosts

Echo 192.168.2.188 club.szshequ.com > C:\ WINDOWS\ system32\ drivers\ etc\ hosts

Echo 192.168.2.188 shop.szshequ.com > C:\ WINDOWS\ system32\ drivers\ etc\ hosts

Echo 192.168.2.188 images.szshequ.com > C:\ WINDOWS\ system32\ drivers\ etc\ hosts

Echo 192.168.2.188 files.szshequ.com > C:\ WINDOWS\ system32\ drivers\ etc\ hosts

Echo 192.168.2.188 ajax.szshequ.com > C:\ WINDOWS\ system32\ drivers\ etc\ hosts

Thank you for reading this article carefully. I hope the article "how to modify host documents with batch processing" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles files code one line backup two value interest at the same time that is time more friends knowledge editing scripts industry information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS Apple NVidia MySQL