如何获取MAC地址 [英] How to get a mac address

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

问题描述

我可以得到连接到我的网站MAC地址。

Can I get a MAC address that are connected to my site.

这code获取的MAC地址的主机和返回错误的权限。

this code get mac address host and return error permission.

  String macadress = string.Empty;

        foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
        {
            OperationalStatus ot = nic.OperationalStatus;
            if (nic.OperationalStatus == OperationalStatus.Up)
            {
                macadress = nic.GetPhysicalAddress().ToString();
                break;
            }
        }

        return macadress;

现在怎么能得到mac地址的用户???

now how can get mac address users???

2。
怎样才能得到用户的ip ???

2. how can get ip users???

推荐答案

可惜你不能得到你想要的方式向用户的MAC地址。这是我的理解,MAC地址是从分组中剥离,当他们离开你的本地网络。

Unfortunately you can't get the user's MAC address in the way that you want. It's my understanding that MAC addresses are stripped from packets when they leave your local network.

您可以的尝试的从 Request.UserHostAddress 获取用户的地址。但是,如果你是在负载平衡器或内容分发网络,那么你可能想尝试寻找在 Request.Headers [X - 转发,对于] 第一 - 这是当该请求被某物转发的用户原始IP地址将经常被写入。

You can try to get the user's address from Request.UserHostAddress. However if you are behind a load balancer or content distribution network then you might want to try looking in Request.Headers["X-Forwarded-For"] first - this is where the users original IP address will often be written when the request is forwarded on by something.

我通常会采取的方法是尝试线沿线的东西:

The approach I'll usually take is to try something along the lines of:

var address = Request.Headers["X-Forwarded-For"];
if (String.IsNullOrEmpty(address))
    address = Request.UserHostAddress;

最后一个项目,我的工作,我们其实都记录,万一送交头已被伪造。

The last project I worked on, we actually logged both, in case the forwarded for header had been faked.

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

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