[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
回复 1# MF9593
  1. @echo off
  2. @setlocal enabledelayedexpansion
  3. rem 目前支持 add , backup , quit
  4. rem 格式:
  5. rem add 域名 [IP地址]
  6. rem backup
  7. rem quit
  8. rem Ps : []中的内容表示非必须
  9. rem 我有空再慢慢打磨 , 添加 del 和 restore
  10. set host="%windir%\system32\drivers\etc\hosts"
  11. set back="%windir%\system32\drivers\etc\hosts_%date:~0,4%_%date:~5,2%_%date:~8,2%_%time:~0,2%_%time:~3,2%.bak"
  12. rem set host="hosts"
  13. rem set back="hosts_%date:~0,4%_%date:~5,2%_%date:~8,2%_%time:~0,2%_%time:~3,2%.bak"
  14. attrib -R %host%
  15. :main
  16.     rem 主循环
  17.     set "command="
  18.     set /P command=
  19.     if "%command%"=="" (
  20.         goto:main
  21.     )
  22.     for /F "tokens=1-26" %%a in ("%command%") do (
  23.         if /I "%%a"=="add" call:add %%b %%c
  24.         if /I "%%a"=="backup" call:backup
  25.         if /I "%%a"=="quit" call:quit
  26.         echo done
  27.     )
  28. goto:main
  29. rem ----------
  30. :add
  31.     rem 添加IP和域名
  32.     rem 若IP缺省则通过ping获取
  33.     set address=%~1
  34.     if "%~2"=="" (
  35.         call:get_IP %address%
  36.     ) else (
  37.         set ip=%~2
  38.     )
  39.     echo %ip% %address% >>%host%
  40. goto:eof
  41. :get_IP
  42.     for /F "skip=6" %%i in ('ping %~1') do (
  43.         set IP=%%i
  44.         goto:eof
  45.     )
  46. goto:eof
  47. rem ----------
  48. :backup
  49.     copy %host% %back%
  50. goto:eof
  51. rem ----------
  52. :quit
  53.     attrib +R %host%
  54. exit
复制代码
3

评分人数

TOP

返回列表