How to match IP address by using 'findstr'? Or any other method of batch in windows

前端 未结 5 1408
广开言路
广开言路 2021-01-21 07:30

    As the title said, I want to match ip address with batch in windows, please tell me how I can do it?
    I see that \"finds

5条回答
  •  后悔当初
    2021-01-21 08:35

    Since findstr's regex support is a bit ... dated, you usually can't use most regexes you find on the web. The following matches four runs of digits, separated by dots:

    ipconfig | findstr /r "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"
    

    However, if you're only interested in addresses and not the subnet masks, you might want to use

    ipconfig | findstr /r "Address.*[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"
    

    And yes, if would also match things like Address: 232345.534.78678.345 which is obviously not an IP address. But usually ipconfig doesn't spit out such strings.

提交回复
热议问题