登录帐号与客服端电脑绑定的问题!200分请教,

atpains atpains 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
还有100分解决后补上

登录帐号与客服端电脑绑定.
小弟 是 使用 MAC地址,获取客户端电脑的MAC地址,与帐号绑定。
获取客户端电脑MAC地址的类如下:(参考别人的,嘿嘿)
在本地测试时,能正常使用。服务器电脑和客户端电脑在同一局域网内。
但是把网站发布在公网的服务器上时,在局域网电脑访问是就不能正确获取MAC地址,返回string.Empty。

是这类不行吗? 还是我的思路错误了,大家都怎么实现这功能的哦。先谢谢了!


using System;
using System.Runtime.InteropServices;


namespace Hnsj.Wholesale.BLL
{
public class GetClientMac
{
[DllImport("Iphlpapi.dll")]
private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
[DllImport("Ws2_32.dll")]
private static extern Int32 inet_addr(string ip);

public GetClientMac()
{

}

/**/
/// <summary>
/// 获取客户端的MAC地址
/// </summary>
/// <param name="IP">客户端IP</param>
/// <returns>客户端的MAC地址</returns>
public string GetMac(string IP)
{
string mac_dest = "";
try
{

string strClientIP = IP;
Int32 ldest = inet_addr(strClientIP); //目的地的ip
Int64 macinfo = new Int64();
Int32 len = 6;
int res = SendARP(ldest, 0, ref macinfo, ref len);
string mac_src = macinfo.ToString("X");
if (mac_src == "0")
{
return string.Empty;
}

while (mac_src.Length < 12)
{
mac_src = mac_src.Insert(0, "0");
}

for (int i = 0; i < 11; i++)
{
if (0 == (i % 2))
{
if (i == 10)
{
mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2));
}
else
{
mac_dest = "-" + mac_dest.Insert(0, mac_src.Substring(i, 2));
}
}
}
}
catch
{

}

return mac_dest;
}
}
}
...全文
评论 22
收藏 已收藏
分享
返回顶部
atpains
.NET社区 62,271 成员 668,968 内容