IP verification in batch script - first match by findstr, secondly verify by for loops (only using windows built in functinallity?

前端 未结 4 1956
没有蜡笔的小新
没有蜡笔的小新 2021-01-06 23:36

This is a question for the batch pro\'s i guess. Seems a lot of people do stumble over IP veriffication while batching, while just using windows built in functinallity, but

4条回答
  •  抹茶落季
    2021-01-07 00:11

    there is no GNU BRE to validate dotted IPs. FINDSTRs REGEX capabilities are below that. You can use grep for Windows and GNU ERE:

    ECHO(%IP%|GREP -E "(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])"&&ECHO %IP% IS VALID/||%IP% IS NOT A VALID IP.
    

提交回复
热议问题