我正在尝试获取特定适配器的ipv4地址(比如以太网适配器Local Area Connection * 14)是否有任何命令或脚本在Windows 10中执行此操作。如果有人已经在过去做过感谢分享它。
输入 - 适配器名称
输出 - 仅适配器的IP地址
答案 0 :(得分:0)
使用netsh
在批处理文件中
@echo off
for /f "tokens=3 delims=: " %%I in ('netsh interface IPv4 show addresses "Ethernet adapter Local Area Connection" ^| findstr /C:"IP Address"') do echo %%I
如果从命令行使用而不是批处理,请删除%
中%%I
的一组,如下所示。
for /f "tokens=3 delims=: " %I in ('netsh interface IPv4 show addresses "Ethernet adapter Local Area Connection" ^| findstr /C:"IP Address"') do echo %I
答案 1 :(得分:0)
您可以尝试使用此批处理脚本来获取:
专用LAN IP(ipv4)
外部公共知识产权
MAC地址
@echo off
Title Get (LAN ,Public) (IP) and MAC Addresses by Hackoo 2017
mode con cols=80 lines=5 & Color 9E
echo( & echo(
echo Please Wait a While ... Searching for (LAN ,Public)(IP) and MAC addresses ...
Set "LogFile=%~dpn0.txt"
@for /f "delims=[] tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do (
set "LAN_IP=%%a"
)
for /f "tokens=2 delims=: " %%A in (
'nslookup myip.opendns.com. resolver1.opendns.com 2^>NUL^|find "Address:"'
) Do set ExtIP=%%A
@For /f %%a in ('getmac /NH /FO Table') do (
@For /f %%b in ('echo %%a') do (
If /I NOT "%%b"=="N/A" (
Set "MY_MAC=%%b"
)
)
)
Cls
echo(
echo My Private LAN IP : %LAN_IP%
echo My External Public IP : %ExtIP%
echo MAC Addres : %MY_MAC%
(
echo My Private LAN IP : %LAN_IP%
echo My External Public IP : %ExtIP%
echo MAC Address : %MY_MAC%
)>"%LogFile%"
Timeout /T 5 /NoBreak>nul
Start "" "%LogFile%"