欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

批處理添加多個新的域名到hosts

 更新時間:2015年09月22日 09:22:05   投稿:hebedich  
本文給大家分享的是使用批處理添加多個新的域名到hosts并進行檢測的思路和代碼,非常的簡單實用,有需要的小伙伴可以參考下

要求:批處理(.bat) 添加多個新的域名到hosts,先檢測是否已存在,如果已存在的域名就不添加

其他尚未存在的域名,則直接添加

google搜尋是有找到代碼  如下:

復(fù)制代碼 代碼如下:

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

不過此代碼只能檢測一行域名

如果要添加以下各種不同域址,如何改寫代碼才能檢測多個的域名?

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

方法一:

@echo off & setlocal enabledelayedexpansion
set "file=%systemroot%\system32\drivers\etc\hosts"
for /f "tokens=2" %%i in ('more +11 "%~0"') do set #%%i=1
for /f "delims=" %%i in ('findstr /n .* %file%') do (
  set "s=%%i"
  set "s=!s:*:=!"
  for /f "tokens=1,2" %%j in ("#!s!") do if not defined #%%k echo;!s!
)
more +11 "%~0"
pause & exit

方法二:帶上檢測功能(各種域址寫在名為list.txt的文件中,一行一個)

@echo off
if exist %temp%\$ del /q %temp%\$
for /f "delims=" %%i in (%systemroot%\system32\drivers\etc\hosts) do echo %%i>>%temp%\$
for /f "delims=" %%a in ('findstr /v /g:"%temp%\$" list.txt') do echo %%a>> %systemroot%\system32\drivers\etc\hosts

相關(guān)文章

最新評論