繁体   English   中英

Windows batch命令从主机文件中检测IP地址

[英]windows batch command to detect ip address from hosts file

可以帮助我检测没有#的任何语句,即。 使用Windows批处理命令从主机文件(/ system32 / drivers / etc / hosts)中获得未注释的语句?

例如:在该文件中指定的IP地址,该地址将不包含#

这对我有用:

findstr "^[^#]*[0-9a-f][.:][0-9a-f]" c:\windows\system32\drivers\etc\hosts

这将找到非注释行

find /v "#" < hosts

不完全确定这不会留下一些未经过滤的内容。

findstr /R /c:"^[^#]*[0-9a-f:.]" %systemroot%\system32\drivers\etc\hosts

会错误吗? 检测包含无效格式的IP地址解析的行(例如IP地址,无名称),但应删除所有注释/无效行。

这段代码仅显示第一行中没有#的行,希望对您有所帮助:

setlocal EnableDelayedExpansion
for /f "delims=¶ tokens=*" %%A in ('"type %SystemRoot%\System32\drivers\etc\hosts"') do (
   set var=%%A
   if NOT "!var:~0,1!" == "#" (echo !var!)
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM