[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] [已解决]批处理怎样将屏蔽网站批量写入hosts?

本帖最后由 a87750530 于 2011-6-26 21:04 编辑

从恶意网站实验室下载的hosts,里面的内容如下
  1. 115.47.219.95 www.aiqianming.cn
  2. 115.47.219.95 www.77112.com
  3. 115.47.219.95 www.6d6d.net
  4. .....
复制代码
想批量写入hosts文件找到这样的方法:
  1. :hostspb
  2. mode con COLS=80 lines=40
  3. color 0a
  4. echo 115.47.219.95 www.aiqianming.cn >>C:\Windows\System32\Drivers\etc\hosts
  5. echo 115.47.219.95 www.77112.com >>C:\Windows\System32\Drivers\etc\hosts
  6. echo 115.47.219.95 www.6d6d.net >>C:\Windows\System32\Drivers\etc\hosts
  7. type C:\WINDOWS\system32\drivers\etc\hosts
  8. start notepad C:\WINDOWS\system32\drivers\etc\hosts
  9. echo    hosts屏蔽完成...任意键返回
  10. pause >nul  
  11. end
复制代码
上面的方法很是麻烦,每个网站都要在前面加echo  ,后面要加>>C:\Windows\System32\Drivers\etc\hosts
能不能把网址如上面的列出来后,用批处理自动添加前后代码然后写入hosts
请大家帮忙一下!谢谢!
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

  1. @echo off
  2. (for /f "delims=" %%a in (a.txt) do (
  3.    set str=%%a
  4.    setlocal enabledelayedexpansion
  5.    echo;!str:115.=echo 115.!
  6.    endlocal
  7. ))>tem
  8. move tem a.txt
  9. goto 2
  10. :2
  11. for /f "delims=" %%a in (a.txt) do (
  12. echo %%a>>C:\Windows\System32\Drivers\etc\hosts>>b.txt
  13. )
  14. start b.txt
  15. pause
  16. end
复制代码
我写了这样的代码,前面的能替换,结果到这里
  1. :2
  2. for /f "delims=" %%a in (a.txt) do (
  3. echo %%a>>C:\Windows\System32\Drivers\etc\hosts>>b.txt
  4. )
复制代码


就卡住了,能不能想想办法?把这个写入“>>C:\Windows\System32\Drivers\etc\hosts”加入在每行的最后一列

TOP

本帖最后由 a87750530 于 2011-6-26 14:09 编辑

5# tmplinshi
把这个内容“>>C:\Windows\System32\Drivers\etc\hosts”加在每一行的末尾
  1. 如:115.47.219.95 anten3.zoomshare.com
  2. 变成
  3. echo 115.47.219.95 anten3.zoomshare.com >>C:\Windows\System32\Drivers\etc\hosts
复制代码
前面的echo我倒是会了,会面的执行就卡壳了!

超级版主,你写的代码结果测试貌似没有效果!很是深奥!

TOP

  1. @echo off
  2. (for /f "delims=" %%a in (a.txt) do (
  3.    set str=%%a
  4.    setlocal enabledelayedexpansion
  5.    echo;!str:115.=echo 115.!
  6.    endlocal
  7. ))>tem
  8. move tem b.txt
  9. goto 2
  10. :2
  11. for /f "delims=" %%a in (b.txt) do (
  12. echo %%a^>^>C:\Windows\System32\Drivers\etc\hosts>>c.txt
  13. )
  14. start c.txt
  15. end
复制代码
搞定了,谢谢版主!

TOP

实在是佩服各位版主的代码,其实是想做个批处理的小工具,结果发现自己水平实在是太低了,只好走点低级的分部完成了。谢谢各位了!
回复batman,你给的代码难道是这样用吗?实在深奥!
  1. @echo off
  2. (for /f "skip=4 delims=" %%a in (%~fs0) do echo %%a)>%systemroot%\dirvers\etc\hosts
  3. goto :eof
  4. 115.47.219.95 www.aiqianming.cn
  5. 115.47.219.95 www.77112.com
  6. 115.47.219.95 www.6d6d.net
  7. ..........省略N个网址!
复制代码

TOP

返回列表