Windows7 Batch, how to break after first For loop

前端 未结 2 1894
不知归路
不知归路 2021-01-16 09:03

I\'m writing a simple script to retreive my localhost address given as IP.

To get my IPv4 address (Win7) I\'ve written simple FOR loop, but as a result i get the IP

相关标签:
2条回答
  • 2021-01-16 09:31

    And what about this code without any loop ?

    @Echo off
    For /f "tokens=2 delims= " %%a in ('arp -a ^|findstr /i "Interface"') do (set IP=%%a)
    Echo The IP adress is : %IP%
    pause
    
    0 讨论(0)
  • 2021-01-16 09:41

    Also code with @aschipfl :SKIP solution

    for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IPv4"') do (
      set ip=%%b
      goto :SKIP
    )
    :SKIP
    set ip=%ip:~1%
    echo %ip%
    
    0 讨论(0)
提交回复
热议问题