如何通过asp.net mvc c#获取浏览网站的客户端的mac地址

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8756179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 04:16:41  来源:igfitidea点击:

how to get mac address of client that browse web site by asp.net mvc c#

c#asp.netasp.net-mvc

提问by titi

I'm trying to get mac address from the client's machine that browse my web site, I've been used this:

我正在尝试从浏览我网站的客户端机器获取 mac 地址,我已经使用过这个:

using System.Management;
class Sample_ManagementClass
{
    public static int Main(string[] args)
    {
        ManagementClass objMC = new
        ManagementClass("Win32_NetworkAdapterConfiguration");
        ManagementObjectCollection objMOC = objMC.GetInstances();

        foreach (ManagementObject objMO in objMOC)
        {
            if (!(bool)objMO["ipEnabled"])
                continue;

            Console.WriteLine((string)objMO["MACAddress"]);
        }
    }
 }

But it is not recognized Management Namespace, so what should I do?

但是不能识别管理命名空间,我该怎么办?

采纳答案by jim tollan

it's unfortunately not possible to reliably get the mac address of the client machine due to firewalls, proxies and ISP generic addresses being given. However, you can make a stab at getting the ip address by using:

不幸的是,由于提供了防火墙、代理和 ISP 通用地址,无法可靠地获取客户端计算机的 mac 地址。但是,您可以尝试使用以下方法获取 IP 地址:

var remoteIpAddress = Request.UserHostAddress;

However, this may or may not actually represent the client machine and is more likely the ISP gateway or some other ip address. It's a well known problem and one that even google have found hard to crack using clientside javascript (the idea here being that you get the actual local ip address via a js library and pass that over to your server function).

但是,这实际上可能代表也可能不代表客户端机器,更可能是 ISP 网关或其他一些 IP 地址。这是一个众所周知的问题,即使是 google 也发现使用客户端 javascript 难以破解(这里的想法是您通过 js 库获取实际的本地 IP 地址并将其传递给您的服务器功能)。

[edit]- might be worth taking a look at the following for inspiration/confirmation of the issue:

[编辑]- 可能值得一看以下内容以获得灵感/确认问题:

http://www.dotnetfunda.com/forums/thread2088-how-to-get-mac-address-of-client-machine.aspx

http://www.dotnetfunda.com/forums/thread2088-how-to-get-mac-address-of-client-machine.aspx

回答by Chris

It is usually not possible for a person to get the MAC address of a computer from its IP address alone. These two addresses originate from different sources. Simply stated, a computer's own hardware configuration determines its MAC address while the configuration of the network it is connected to determines its IP address. However, computers connected to the same TCP/IP local network can determine each other's MAC addresses. The technology called ARP - Address Resolution Protocol included with TCP/IP makes it possible. Using ARP, each computer maintains a list of both IP and MAC addresses for each device it has recently communicated with.

一个人通常不可能仅从计算机的 IP 地址获取计算机的 MAC 地址。这两个地址来自不同的来源。简单地说,计算机自身的硬件配置决定了它的 MAC 地址,而它所连接的网络的配置决定了它的 IP 地址。但是,连接到同一 TCP/IP 本地网络的计算机可以确定彼此的 MAC 地址。TCP/IP 中包含的称为 ARP(地址解析协议)的技术使之成为可能。使用 ARP,每台计算机都会为它最近与之通信的每个设备维护一个 IP 和 MAC 地址列表。

Src

来源