![](/img/trans.png)
[英]How would I run an ifconfig, grab the IPV4 address, place it in a variable and then output the results in shell?
[英]How to grab IPV4 variable in CMD and Ping in new CMD window
所以這是一個想法,我試圖從 Cmd 中獲取一個變量,例如 IPv4,並能夠在新窗口中對其進行 ping 操作。
通過運行命令並獲取該命令的特定部分並能夠在新命令行中將其作為新變量輸入以便執行操作,邏輯是什么。
另一個例子 :
我目前正在下載 Visual Basics 軟件,因為它看起來可能是我可能需要但非常困惑的語言。
有沒有人對我可以使用的內容有任何基本想法或有這樣的例子?
你可以嘗試這樣的事情:
@Echo off
Color 0A & Mode con cols=80 lines=15
Title How to grab IPv4
::**********************************
::Method1
::**********************************
echo(
echo Method 1 with arp -a
echo(
For /f "tokens=2 delims= " %%a in ('arp -a ^|findstr /i "Interface"') do (set IP=%%a)
Echo The Local IPv4 adress is : %IP%
pause
Cls
Call:PingHost %IP%
pause
::**********************************
::Method2
::**********************************
cls
echo(
echo Method 2 with ipconfig
for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IPv4"') do (
set ip=%%b
)
set ip=%ip:~1%
echo(
echo The Local IPv4 adress is : %ip%
pause
Cls
Call:PingHost %IP%
pause
::**********************************
::Method3 by Stephan
::**********************************
cls
echo(
echo Method 3 with %%computername%% = %computername%
for /f "tokens=2 delims=[]" %%i in ('ping -4 -n 1 %computername%') do set ip=%%i
echo(
echo The Local IPv4 adress is : %ip%
pause
Cls
Call:PingHost %IP%
Pause
exit
::**********************************
:Pinghost
Start "%1" Ping %1
exit /b
::**********************************
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.