MSYS2:windows下获取ip地址对应的网卡名

本文介绍了一种使用Netsh命令结合Sed工具来获取并过滤计算机中各网络接口IPv4地址信息的方法。通过特定的正则表达式匹配与删除不必要的输出内容,实现了对网络接口配置信息的有效提取。

基本的原理就是用netsh interface ipv4 show address命令列出所有网卡的地址信息,然后用sed过滤掉无用的内容,具体实现如下:

$  netsh interface ipv4 show address |\
	sed -E -e '/(DHCP enabled|Subnet Prefix|InterfaceMetric|Default Gateway|Gateway Metric)/d' |\
	sed -e '/Configuration/{ N ; s/\n/ / }' |\
 	sed -E -e 's/(Configuration for interface|IP Address)//g' -e '/^$/d'

输出:

“Npcap Loopback Adapter” : 169.254.154.214
“本地连接 2”
“本地连接” : 192.168.10.150
“VirtualBox Host-Only Network” : 192.168.56.1
“Loopback Pseudo-Interface 1” : 127.0.0.1

MSYS: DMEM request: [emac0_buff]:0x00000812 MSYS: DMEM request: [emac0_buff]:0x00000812 success, CPU phy:@0x23846000, virt:@0xC3846000 libphy: mdio: probed mdio_bus mdio-bus@emac0: /soc/emac0/mdio-bus@emac0/ethernet-phy@0 has invalid PHY address mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 0 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 1 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 2 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 3 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 4 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 5 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 6 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 7 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 8 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 9 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 10 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 11 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 12 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 13 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 14 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 15 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 16 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 17 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 18 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 19 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 20 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 21 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 22 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 23 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 24 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 25 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 26 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 27 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 28 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 29 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 30 mdio_bus mdio-bus@emac0: scan phy ethernet-phy at address 31 [emac_phy_connect][3592] connected mac emac0 to PHY at mdio-bus@emac0:00 [uid=11112222, driver=SStar 10/100 Ethernet Phy] MSYS: DMEM request: [emac1_buff]:0x00060812 MSYS: DMEM request: [emac1_buff]:0x00060812 success, CPU phy:@0x23850000, virt:@0xC3850000 libphy: mdio: probed mdio_bus mdio-bus@emac1: /soc/emac1/mdio-bus@emac1/ethernet-phy@1 has invalid PHY address mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 0 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 1 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 2 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 3 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 4 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 5 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 6 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 7 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 8 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 9 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 10 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 11 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 12 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 13 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 14 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 15 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 16 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 17 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 18 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 19 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 20 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 21 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 22 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 23 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 24 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 25 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 26 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 27 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 28 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 29 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 30 mdio_bus mdio-bus@emac1: scan phy ethernet-phy at address 31 [emac_phy_connect][3592] connected mac emac1 to PHY at mdio-bus@emac1:00 [uid=00000000, driver=Generic PHY] MSYS: DMEM request: [AESDMA_ENG]:0x00001000 MSYS: DMEM request: [AESDMA_ENG]:0x00001000 success, CPU phy:@0x23847000, virt:@0xC3847000 MSYS: DMEM request: [AESDMA_ENG1]:0x00001000 MSYS: DMEM request: [AESDMA_ENG1]:0x00001000 success, CPU phy:@0x23848000, virt:@0xC3848000 [ms_cpufreq_init] Current clk=799999872 mstar_spinand_probe: mstar_spinand enableClock MSYS: DMEM request: [BDMA]:0x00000840 MSYS: DMEM request: [BDMA]:0x00000840 success, CPU phy:@0x23849000, virt:@0xC3849000 [emac_phy_link_adjust] EMAC Link Down [emac_phy_link_adjust] EMAC Link Down [emac_phy_link_adjust] EMAC Link Up
最新发布
10-30
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

10km

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值