如何获得默认网卡连接名称 [英] How to get default NIC Connection Name

查看:249
本文介绍了如何获得默认网卡连接名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重要编辑:在这个问题上再返回。
至于你说的应该没有默认网卡,我想知道是否有检测到所有已实际连接的网卡的方式。



有我的物理接口的MAC地址是有一个纲领性的方式来获得接口名称/接口状态/等等...



例如,我的XP机器:



设备Realtek的RTL8139家庭的PCI快速以太网NIC
的MAC XXXX-XXXX-XXXX



XXXX-XXXX-XXXX是我知道的。



通过这个设备我连接使用本地连接连接(与所有相关的网关,子网掩码的信息,...)



所以我在寻找XXXX-XXXX-XXXX和本地连接之间的联系。



希望一切现在很清楚



谢谢大家!
附:抱歉耽搁... +1投票所有,有耐心!






老问题






大家好,
我想通过使用命令netsh改变本地连接的IP地址。



我的问题是有没有一个纲领性的方式来获得默认连接名称(即正是本地连接)?



感谢



编辑:我并不需要所有的连接名称的列表,但只有默认的。访问注册表我得到的名单,似乎默认为标有*。
不幸的是,它们打印一个控制台,我得到10种不同的本地连接上像...

 本地连接* 13 
6TO4适配器
VMware的网络适配器VMnet1的
无线网络连接2
可重复使用的ISATAP接口{483968F2-DBF9-4596-B8BE-725FAAB89F93}
当地时间区域连接* 3
本地连接* 2
可重复使用微软的6to4适配器
本地连接* 7
VMware的网络适配器vmnet8的
本地连接* 8
isatap.replynet.prv
本地连接* 9
本地连接* 12
ISATAP {FAA80CE0-D641-408A-83F8-5F9C394FFD76}
蓝牙网络连接
本地连接* 4
ISATAP {40156BF9-6599-4912-A315-62DE5342B452}
ISATAP。{} 7651F2F5-4888-4258-92C5-6822C506D726
本地连接* 5
ISATAP {34F5F074-8AA7-4421-AE24-131BA2DC3458}
本地连接*
本地连接* 10
本地连接
本地连接* 6
无线网络连接

等等...



EDIT2:@ HO1运行代码改变这种不存在名称,你会得到类似的名单背后的FriendlyName,遗憾的是它似乎不被输出有望

  0  -  WAN微型端口(SSTP)
1 - WAN微型端口(IKEv2协议)
2 - WAN微型端口(L2TP)
3 - WAN微型端口(PPTP)
4 - WAN微型端口(PPPOE)
5 - WAN微型端口(IPv6)的
6 - WAN微型端口(网络监视器)
7 - Realtek的RTL8168C (P)/ 8111C(P)系列PCI-E千兆以太网NIC(NDIS 6.20)
8 - WAN微型端口(IP)
9 - 微软ISATAP适配器
10 - RAS异步适配器
11 - 博通802.11g标准的网络适配器
12 - 微软的6to4适配器
13 - VMnet1的
VMware的虚拟以太网适配器14 - 微软ISATAP适配器#3
15 - VMware的虚拟以太网适配器vmnet8的
16 - 微软ISATAP适配器#2
17 - 微软ISATAP适配器#4
18 - 微软虚拟无线微型端口适配器
19 - 微软ISATAP适配器#5
20分配 - 微软ISATAP适配器
22 - 蓝牙设备(个人局域网)
23 - 微软的6to4适配器
24 - 微软的6to4适配器#3
25 - 微软的6to4适配器#2


解决方案

这是做它,因为它的一个肮脏的方式可以通过将LINQ等进行优化

 使用System.Net.NetworkInformation; 

名单,LT;&NetworkInterface的GT;接口=新的List<&NetworkInterface的GT;();
的foreach(在NetworkInterface.GetAllNetworkInterfaces VAR NIC())
{
如果(nic.OperationalStatus == OperationalStatus.Up)
{
Interfaces.Add(NIC) ;
}
}


NetworkInterface的结果= NULL;
的foreach(在接口的NetworkInterface NIC)
{
如果(结果== NULL)
{
结果=网卡;
}
,否则
{
如果(nic.GetIPProperties()。GetIPv4Properties()!= NULL)
{
如果(nic.GetIPProperties() 。.GetIPv4Properties()指数< result.GetIPProperties()GetIPv4Properties()指数)
结果=网卡。;
}
}
}

Console.WriteLine(result.Name);

您可能想通过使用的结果来定制你的结果NIC .GetIPProperties() nic.GetIPProperties()。GetIPv4Properties()


IMPORTANT EDIT: Back again on this subject. As you said there should be no default NIC, I'm trying to understand if there is a way to detect all the NICs that are actually connected.

Having the MAC address of my physical interface is there a programmatic way to get interface name/interface status/etc...

For example, my XP machine:

Device Realtek RTL8139 Family PCI Fast Ethernet NIC MAC XXXX-XXXX-XXXX

XXXX-XXXX-XXXX is what I know

Through this device I connect using "Local Area Connection" connection (with all the info related as gateway, subnet, ...)

So I'm searching for the link between XXXX-XXXX-XXXX and Local Area Connection.

Hope everything is clear now.

Thanks all! P.S. Sorry for the delay... +1 vote to all, for patience!


Old question


Hi all, I'd like to change the IP of "Local Area Connection" by using the command netsh.

My issue is is there a programmatic way to get the default connection name (i.e. exactly "Local Area Connection")?

Thanks

EDIT: I don't need the list of all the connection names but only the default one. Accessing the registry I get the list and it seems that the default is marked with a *. Unfortunately, printing them on a console I get kind of 10 different "Local Area Connection" like...

Local Area Connection* 13
6TO4 Adapter
VMware Network Adapter VMnet1
Wireless Network Connection 2
Reusable ISATAP Interface {483968F2-DBF9-4596-B8BE-725FAAB89F93}
Local Area Connection* 3
Local Area Connection* 2
Reusable Microsoft 6To4 Adapter
Local Area Connection* 7
VMware Network Adapter VMnet8
Local Area Connection* 8
isatap.replynet.prv
Local Area Connection* 9
Local Area Connection* 12
isatap.{FAA80CE0-D641-408A-83F8-5F9C394FFD76}
Bluetooth Network Connection
Local Area Connection* 4
isatap.{40156BF9-6599-4912-A315-62DE5342B452}
isatap.{7651F2F5-4888-4258-92C5-6822C506D726}
Local Area Connection* 5
isatap.{34F5F074-8AA7-4421-AE24-131BA2DC3458}
Local Area Connection*
Local Area Connection* 10
Local Area Connection
Local Area Connection* 6
Wireless Network Connection

and so on...

EDIT2: @ho1 running your code changing FriendlyName that doesn't exists with Name you'll get something like the list behind, unfortunately it doesn't seem to be the output expected

0 - WAN Miniport (SSTP)
1 - WAN Miniport (IKEv2)
2 - WAN Miniport (L2TP)
3 - WAN Miniport (PPTP)
4 - WAN Miniport (PPPOE)
5 - WAN Miniport (IPv6)
6 - WAN Miniport (Network Monitor)
7 - Realtek RTL8168C(P)/8111C(P) Family PCI-E Gigabit Ethernet NIC (NDIS 6.20)
8 - WAN Miniport (IP)
9 - Microsoft ISATAP Adapter
10 - RAS Async Adapter
11 - Broadcom 802.11g Network Adapter
12 - Microsoft 6to4 Adapter
13 - VMware Virtual Ethernet Adapter for VMnet1
14 - Microsoft ISATAP Adapter #3
15 - VMware Virtual Ethernet Adapter for VMnet8
16 - Microsoft ISATAP Adapter #2
17 - Microsoft ISATAP Adapter #4
18 - Microsoft Virtual WiFi Miniport Adapter
19 - Microsoft ISATAP Adapter #5
20 - Microsoft ISATAP Adapter
22 - Bluetooth Device (Personal Area Network)
23 - Microsoft 6to4 Adapter
24 - Microsoft 6to4 Adapter #3
25 - Microsoft 6to4 Adapter #2

解决方案

This is a dirty way of doing it as it can be optimized by incorporating LINQ, etc

using System.Net.NetworkInformation;

List<NetworkInterface> Interfaces = new List<NetworkInterface>();
foreach (var nic in NetworkInterface.GetAllNetworkInterfaces())
{
    if (nic.OperationalStatus == OperationalStatus.Up)
    {
        Interfaces.Add(nic);
    }
}


NetworkInterface result = null;
foreach (NetworkInterface nic in Interfaces)
{
    if (result == null)
    {
        result = nic;
    }
    else
    {
        if (nic.GetIPProperties().GetIPv4Properties() != null)
        {
            if (nic.GetIPProperties().GetIPv4Properties().Index < result.GetIPProperties().GetIPv4Properties().Index)
                result = nic;
        }
    }
}

Console.WriteLine(result.Name);

you'll probably want to tailor your results by using the results from nic.GetIPProperties() and nic.GetIPProperties().GetIPv4Properties()

这篇关于如何获得默认网卡连接名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆