标题: [网络连接] [分享]批处理根据用户输入数字输出对应的网卡名称 [打印本页]
作者: Batcher 时间: 2023-10-8 11:11 标题: [分享]批处理根据用户输入数字输出对应的网卡名称
【问题描述】
我之前遇到一个难题 烦请帮忙看下 如何才能输出对应的网卡- @echo off
- echo 获取所有在线网卡名称
- echo.
- setlocal enabledelayedexpansion
- set "interfaces="
- set "count=1"
- for /f "tokens=4,* skip=3 delims= " %%i in ('netsh interface show interface') do (
- echo !count!. %%i %%j
- set "interface=%%i %%j"
- REM 将在线网卡添加到列表中
- set "interfaces=!interfaces! !count!.!interface!"
- set /a "count+=1"
- )
- echo.
- ::选择要修改的网卡编号
- set /p "selected_number=请选择要修改的网卡编号:"
- echo.
- ::查找选择的网卡
- for %%i in (%interfaces%) do (
- if "%%i"=="%selected_number%" (
- set "selected_interface=%%i"
- )
- )
- ::从选择的网卡中提取网卡名称
- echo 选择的网卡名称:%selected_interface%
- echo.
- pause
复制代码
作者: Batcher 时间: 2023-10-8 11:12
【解决方案】- @echo off
- echo 获取所有在线网卡名称
- setlocal enabledelayedexpansion
- set "count=1"
- for /f "skip=3 tokens=3,*" %%a in ('netsh interface show interface') do (
- echo !count!. %%b
- REM 将在线网卡添加到列表中
- set "_!count!=%%b"
- set /a "count+=1"
- )
- REM 选择要修改的网卡编号
- set /p "selected_number=请选择要修改的网卡编号:"
- REM 查找选择的网卡
- for /f "tokens=1,* delims=_=" %%a in ('set _') do (
- if "%%a" equ "%selected_number%" (
- set "selected_interface=%%b"
- )
- )
- echo 选择的网卡名称:%selected_interface%
- endlocal
- pause
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |