如何获取客户端机器的mac地址? [英] How to get client machine's mac address?

查看:156
本文介绍了如何获取客户端机器的mac地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在开发一个ASP.Net网站。对于用户跟踪,我们需要注册用户登录的客户端计算机的Mac地址。我尝试了两种方法。但在这两种方法中,它都采用服务器mac地址而不是客户端机器。



请有人帮助我,获取客户端机器的mac地址。提前谢谢。



我尝试了什么:



第一种方法

-------------



公共字符串GetMACAddress()

{

var macAddr =

(来自NetworkInterface.GetAllNetworkInterfaces()中的nic

其中nic.OperationalStatus == OperationalStatus.Up

选择nic.GetPhysicalAddress()。ToString())。FirstOrDefault();

返回macAddr;

}



第二种方法

-------------

foreach(NetworkInterface.GetAllNetworkInterfaces()中的NetworkInterface nic) />
{

if(nic.OperationalStatus == OperationalStatus.Up&&(!nic.Description.Contains(Virtual)&&!nic.Description。包含(伪)))

{

if(nic.GetPhysicalAddress()。ToStr ing()!=)

{

mac = nic.GetPhysicalAddress()。ToString();

}

}

}

Hi all,

I'm developing a ASP.Net website. For User Tracking we need to register the Mac Address of the Client Machines where the User logging in. I have tried two methods. but in both methods it is taking server mac address instead of client machine.

Please, anyone help me, to get mac address of the client machine. thanks in advance.

What I have tried:

First Method
-------------

public string GetMACAddress()
{
var macAddr =
(from nic in NetworkInterface.GetAllNetworkInterfaces()
where nic.OperationalStatus == OperationalStatus.Up
select nic.GetPhysicalAddress().ToString()).FirstOrDefault();
return macAddr;
}

Second Method
-------------
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up && (!nic.Description.Contains("Virtual") && !nic.Description.Contains("Pseudo")))
{
if (nic.GetPhysicalAddress().ToString() != "")
{
mac = nic.GetPhysicalAddress().ToString();
}
}
}

推荐答案

简单,你不能。



除了客户机所在的子网外,MAC地址不可见,也没有任何意义。



它不能用于唯一的识别机器,因为它不是一个独特的值,与机器无关。它是网络接口的标识符,而不是机器,因为机器可以有多个网络接口。



您发布的代码仅用于获取其中一个的MAC SERVER中的网络接口,而不是客户端! ASP.NET代码完全在服务器上运行,而不是客户端。
Simple, you can't.

The MAC address isn't visible, nor has any meaning, to anything but the subnet the client machine is on.

It cannot be used to uniquely identify a machine, since it's NOT a unique value and has nothing to do with the machine. It's an identifier for a network interface, not a machine since machines can have multiple network interfaces.

The code you've posted only works to get the MAC of one of the network interfaces in the SERVER, NOT THE CLIENT! ASP.NET code runs entirely on the server, never the client.


user在登录/注册服务器时发送一个/ MAC地址。



MAC指的是NIC;网络接口卡。



MAC识别供应商;和供应商产品识别系统。



供应商可能有多个供应商ID;即使对于相同类型的设备。
The "user" "sends" a / the MAC address when logging in / registering with the server.

The MAC refers to a NIC; a network interface card.

The MAC identifies the vendor; and the vendors product identification system.

A Vendor may have multiple "vendor Ids"; even for the same type of equipment.


正如其他人所提到的,在Web应用程序中识别特定设备没有真正的万无一失的方法。您只需要获取网关的IP地址/ MAC。



我最近有一个Web应用程序,它具有相同的要求来识别用于记录保存的设备。我们想出了一种方法,将设备名称和其他几个关键元素编码到用于启动应用程序的查询字符串中。一旦设备经过验证,相应的cookie也会写入/重写给客户端......但您不能信任cookie。该系统适用于拥有约50个iPad /位置的客户。像往常一样,会话超时是魔鬼...相应的代码!



另一种可能性是创建一个混合应用程序,它基本上是一个Click-Once窗口应用程序,包含一个包含浏览器控件的单个表单。在启动时,获取系统mac地址和/或设备名称,登录用户名等,并通过查询字符串将其传递到Web应用程序。我几年来一直在使用这种方法为几个不同的客户端而且工作正常...它只是限制你使用Windows设备。
As others have mentioned, there is no real fool-proof way of identifying a particular device in a web application. You are only going to get the gateway's IP address/MAC.

I recently had a web application that had the same requirements to identify devices for record keeping. We came up with a method that encodes the device name and a couple of other key elements into the querystring used to launch the app. Once a device has been validated the appropriate cookies are also written/rewritten to the client...but you can't trust cookies. This system is working well for a customer having around 50 iPads/locations. As usual, session timeouts are the devil...code accordingly!

One other possibility is creating a hybrid application that is basically a Click-Once windows application that contains a single form containing a browser control. On startup, get the systems mac address and/or device name, logged in user name, etc. and pass this in through the querystring to your web application. I've been using this method for a few years now for a couple of different clients and it works fine...it just limits you to windows devices.


这篇关于如何获取客户端机器的mac地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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