我在命令行 / 批处理文件中的 Windows 7 系统上。在那里,我可以通过解析“路由打印”的输出来获取网卡的索引:
route print | findstr "Microsoft\ Virtual\ WiFi\ Miniport\ Adapter\ #4"
这给了我输出:
22...58 94 6b 0f 87 65 ......Microsoft Virtual WiFi Miniport Adapter #4
从这个输出我需要得到数字 22,这样我可以在我的脚本中重用它:
set IP1=21
# 22 has to be replaced by the output of the "route print":
set IP2=22
netsh intece ipv4 set address %IP1% static %M_IP% %MASK% gateway=%GW% gwmetric=1
变量% M_IP%% MASK% 和% GW% 也在批处理文件中设置。
[编辑在 2016-10-17]:使用接受的答案,我得到这样的脚本:
@echo off
echo Suche Netzwerkkarten fuer Masterunit V1
echo suche erste Karte:
echo - Intel(R) 82574L Gigabit Network Connection
for /f "tokens=1 delims=. " %%a in ('route print ^| findstr /C:"Intel(R) 82574L Gigabit Network Connection"') do set "IP1_1=%%a"
if "%IP1_1%"=="" goto l1
echo %IP1_1%
goto l1a
:l1
echo keine Karte gefunden
:l1a
echo suche zweite Karte:
echo - Intel(R) 82567LM Gigabit Network Connection
for /f "tokens=1 delims=. " %%a in ('route print ^| findstr /C:"Intel(R) 82567LM Gigabit Network Connection"') do set "IP1_2=%%a"
if "%IP1_2%"=="" goto l2
echo %IP1_2%
goto l2a
:l2
echo keine Karte gefunden
:l2a
echo Suche Netzwerkkarten fuer Masterunit V2 / flexE12CM2K:
echo suche erste Karte:
echo - Intel(R) I210 Gigabit Network Connection
for /f "tokens=1 delims=. " %%a in ('route print ^| findstr /C:"Intel(R) I210 Gigabit Network Connection"') do set "IP2_1=%%a"
if "%IP2_1%"=="" goto l3
echo %IP2_1%
goto l3a
:l3
echo keine Karte gefunden
:l3a
echo suche zweite Karte:
echo - Intel(R) Ethernet Connection I218-LM
for /f "tokens=1 delims=. " %%a in ('route print ^| findstr /C:"Intel(R) Ethernet Connection I218-LM"') do set "IP2_2=%%a"
if "%IP2_2%"=="" goto l4
echo %IP2_2%
goto l4a
:l4
echo keine Karte gefunden
:l4a
echo alles nochmal zusammen gefasst:
echo Masterunit V1: 1. Karte : %IP1_1%
echo Masterunit V1: 2. Karte : %IP1_2%
echo Masterunit V2: 1. Karte : %IP2_1%
echo Masterunit V2: 2. Karte : %IP2_2%
是否可以重命名网络接口(IP1_1 可能被命名为“LAN-Verbindung 2”,而 IP1_2 被命名为“LAN-Verbindung”),并且 IP1_1 必须始终被命名为“ETH_EXT”,IP1_2 必须被命名为“ETH_MSR”。
这同样适用于对 IP2_1 和 IP2_2,因为这两个接口卡表示另一硬件配置。
但是我找不到在使用索引时重命名接口的方法。索引是对接口本身的唯一引用。
for / f "tokens = 1 delims =".% a in ('route print ^ | findstr / C:"Microsoft Virtual WiFi Miniport Adapter # 4"') 请设置 "IP =% a"
小心处理“路由打印”输出,如果特定的网卡由于某种原因被禁用,接口将不会在这里列出。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(25条)