To modify the code of the host file with batch processing _dos/bat

Source: Internet
Author: User
Tags eol goto
@echo 127.0.0.1 baidu.com >>c:\windows\system32\drivers\etc\hosts
This is to change one line of writing.
If you want to change another line, write:
Copy Code code 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


Copy Code code 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



Because the test needs to modify the native host frequently, you can modify it by scripting:
Do two batch processing, one intranet, one extranet, switch operation when using
such as intranet. bat
Copy Code code as follows:

CD/D%windir%\system32\drivers\etc
Del Hosts.bak//delete original backup file
ren hosts Hosts.bak//Backup now Host
for/f "eol=# tokens=1,2"%%i in (Hosts.bak) do Call:checkvalue%%i
Goto END
: CheckValue
Echo%2 | find/i "szshequ.com"/seek to make record deletion
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.