0

我需要获取路由器的 MAC 地址,以便在我的程序中像标识符一样使用它。

我的电脑使用以太网电缆连接到路由器

有没有办法获取 MAC,如果有,有没有办法使用 C# 更改或克隆它?

我需要获取路由器MAC地址而不是我的网卡MAC地址...

我看到这样的种子从C#获取无线接入点的BSSID(MAC地址) ...如果可以获取无线的MAC地址设备,是否可以获得连接的以太网设备的 MAC 地址?

4

2 回答 2

1

From a little more research there is no managed API that will let you do this. You need to either use the Windows API method described in How do I access ARP-protocol information through .NET? and http://www.pinvoke.net/default.aspx/iphlpapi.sendarp or you need to start a shell to run arp -a and capture the result.

于 2013-04-29T12:39:11.020 回答
1

您可能会寻求这个答案:获取默认网关

public static IPAddress GetDefaultGateway()
{
    var card = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault();
    if(card == null) return null;
    var address = card.GetIPProperties().GatewayAddresses.FirstOrDefault();
    return address.Address;
}

编辑(这是你寻求的):

var macAddr =
(
    from nic in NetworkInterface.GetAllNetworkInterfaces()
    where nic.OperationalStatus == OperationalStatus.Up
    select nic.GetPhysicalAddress().ToString()
).FirstOrDefault();
于 2013-04-29T09:46:07.767 回答