In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to add multiple new domain names to hosts in batch processing". The explanation in this article is simple and clear, and easy to learn and understand. please follow the editor's ideas to study and learn "how to batch add multiple new domain names to hosts".
Requirement: batch process (.bat) to add multiple new domain names to hosts, first check whether they already exist, and do not add them if they already exist.
For other domain names that do not already exist, add them directly
Google search is found with the following code
The code is as follows:
Set stHosts= X.X.X.X www.domainname.com
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
However, this code can only detect one line of domain names.
If you want to add the following different domain addresses, how can I rewrite the code to detect multiple domain names?
127.0.0.1 mcfg.sandai.net
127.0.0.1 211.94.190.80
127.0.0.1 advstat.xunlei.com
123.87.86.5 biz5.sandai.net
527.66.13.125 cknum.sandai.net
110.45.215.113 cl.kankan.xunlei.com
127.0.0.1 float.sandai.net
127.0.0.1 mcfg.sandai.net
180.70.134.154 mtips.xunlei.com
127.0.0.1 pubstat.sandai.net
216.58.221.74 recommend.xunlei.com
127.0.0.1 wy.xunlei.com
110.45.229.148 buy.safe.xunlei.com
Method 1:
@ echo off & setlocal enabledelayedexpansionset "file=%systemroot%\ system32\ drivers\ etc\ hosts" for / f "tokens=2"% I in ('more + 11 "% ~ 0"') do set #% i=1for / f "delims="%% I in ('findstr / n. *% file%') do (set "slots% I" set "slots) For / f "tokens=1,2" j in ("#! s!") Do if not defined #% k echosmarts!) more + 11 "% ~ 0" pause & exit
Method 2: bring the detection function (various domain addresses are written in a file named list.txt, one per line)
@ echo offif exist% temp%\ $del / Q% temp%\ $for / f "delims="% I in (% systemroot%\ system32\ drivers\ etc\ hosts) do echo% I > >% temp%\ $for / f "delims="% an in ('findstr / v / g: "% temp%\ $" list.txt') do echo% a > >% systemroot%\ system32\ drivers\ etc\ hosts Thank you for your reading. This is the content of "how to batch add multiple new domain names to hosts". After the study of this article, I believe you have a deeper understanding of how to add multiple new domain names to hosts in batch processing, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.