如何抢在新的CMD窗口CMD和平安IPV4变量 [英] How to grab IPV4 variable in CMD and Ping in new CMD window
问题描述
因此,这里是思想,
我想抓住从Cmd的,如IPv4一个变量,能够ping它在一个新的窗口。
So here is the idea, I am trying to grab a variable from Cmd such as IPv4 and be able to ping it in a new window.
将逻辑是什么通过运行一个命令并抓住该命令的特定部分,并能够输入其作为新vairable在一个新的命令行,因此可以执行一个动作。
What would the logic be by running a command and grabbing a specific part of that command and be able to input it as a new vairable in a new command line so it can perform an action.
另外一个例子:
- 找到计算机的名称。
- 在计算机名称末尾运行命令的一个数字。
我目前下载的视觉基础软件,因为它看起来像它可能是语言,我可能需要,但很困惑。
I am currently downloading Visual Basics software as it looks like it may be the language i may need but very confused.
没有人有任何基本的想法是什么,我可以使用或有这方面的一个例子吗?
Does anyone have any basic idea as to what i can use or have an example of this ?
推荐答案
您可以尝试这样的事情:
You can try something like that :
@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
::**********************************
这篇关于如何抢在新的CMD窗口CMD和平安IPV4变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!