gpt4 book ai didi

batch-file - 如果不存在,获取以太网的 IP 地址,然后使用批处理脚本获取 WIFI 适配器

转载 作者:行者123 更新时间:2023-12-03 20:47:05 25 4
gpt4 key购买 nike

我有一个批处理脚本,它获取机器的 IP 地址,如果不存在,则检索 WIFI 适配器的 IP 地址。它适用于以太网适配器,但是当它找到 WIFI 适配器时,它在某些系统上工作但在其他系统上失败,因为我发现 WIFI 适配器的名称在不同的系统上不同。我对批处理脚本了解不多。
这是我试过的脚本。

@echo off
setlocal enabledelayedexpansion
::just a sample adapter here:
set "adapter=Ethernet adapter Ethernet"
set adapterfound=false
echo Network Connection Test
echo %new%
for /f "usebackq tokens=1-2 delims=:" %%f in (`ipconfig`) do (
set "item=%%f"
if /i "!item!"=="!adapter!" (
echo found
set adapterfound=true
) else if not "!item!"=="!item:IPv4 Address=!" if "!adapterfound!"=="true" (
set _IPaddr=%%g
echo Your IP Address is: %%g
goto :break
rem set adapterfound=false
rem echo not found
)
rem echo adapterfound
)

:break
if "!adapterfound!"=="false" (

:: sometimes I get another name like "adapter=Wireless LAN adapter Wi-Fi 2"

set "adapter=Wireless LAN adapter Wireless Network Connection"
set adapterfound=false
echo Network Connection Test
for /f "usebackq tokens=1-2 delims=:" %%f in (`ipconfig`) do (
set "item=%%f"
if /i "!item!"=="!adapter!" (
echo found
set adapterfound=true
) else if not "!item!"=="!item:IPv4 Address=!" if "!adapterfound!"=="true" (
set _IPaddr=%%g
echo Your IP Address of WIFI is: %%g
set adapterfound=false
)
)
)
for /f "tokens=* delims= " %%a in ("%_IPaddr%") do set _IPaddr=%%a
echo %_IPaddr%

最佳答案

请试一试:

@echo off
setlocal enabledelayedexpansion
for /f "tokens=2,3 delims={,}" %%a in ('"wmic nicconfig where IPEnabled="True" get DefaultIPGateway /value | find "I" "') do set gate_test=%%~a
set gate_test=!gate_test: =!
for /f "tokens=1-3 delims=^." %%i in ("!gate_test!") do set range=%%i.%%j.%%k
for /f "tokens=1,2 delims=:" %%l in ('ipconfig ^| findstr IPv4') do (
set ip=%%m
set ip=!ip: =!
for /f "tokens=1-3 delims=^." %%n in ("!ip!") do set iprange=%%n.%%o.%%p
if !iprange! == !range! set ipaddress=!ip!
)
)
echo My IP Address is !ipaddress!

关于batch-file - 如果不存在,获取以太网的 IP 地址,然后使用批处理脚本获取 WIFI 适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52076166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com