获取唯一客户端ID [英] Get unique client Id

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

问题描述

大家好

我正在尝试获取客户端机器的唯一ID但网络防火墙不允许我获取我已经尝试过IP,MACID,处理器ID以及母板ID但所有给我服务器特定的网络价值而非客户端机器。

如果有任何想法,请告诉我。



使用以下代码

 私人  void  UpdateOnlineUsers()
{

int userId = Convert。 ToInt32(会话[ userId]。ToString());
// string clientIp =(Request.ServerVariables [HTTP_X_FORWARDED_FOR] ?? Request.ServerVariables [REMOTE_ADDR ])。分割(',')[0] .Trim();
string clientIp = string .Concat(GetMaccID(),cpuId());
user.UpdateOnlineUsers(userId,clientIp, false );
}
// 返回硬件标识符
私有 静态 字符串标识符( string wmiClass, string wmiProperty)
{
string result = ;
System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection moc = mc.GetInstances();
foreach (System.Management.ManagementObject mo in moc)
{
// 只获得第一个
if (result ==
{
try
{
result = mo [wmiProperty] .ToString();
break ;
}
catch
{
}
}
}
return 结果;
}
私有 静态 string cpuId()
{
// 使用第一个可用的CPU标识符首选项
// 不要获取所有标识符,因为它非常耗时
string retVal = identifier( Win32_Processor UniqueId);
if (retVal == // 如果没有UniqueID,请使用ProcessorID
{
retVal = identifier( Win32_Processor ProcessorId);
if (retVal == // 如果没有ProcessorId,请使用名称
{
retVal = identifier( Win32_Processor 名称);
if (retVal == // 如果没有名称,请使用制造商
{
retVal = identifier( Win32_Processor 制造商);
}
// 添加时钟速度以增加安全性
retVal + =标识符( Win32_Processor MaxClockSpeed);
}
}
return retVal;
}
// 主板ID
private static string baseId()
{
返回标识符( Win32_BaseBoard 模型
+ identifier( Win32_BaseBoard 制造商
+ identifier( Win32_BaseBoard 名称
+ identifier( Win32_BaseBoard 的SerialNumber);
}
私有 字符串 GetMaccID()
{
string macID = string .Empty;
foreach (System.Net.NetworkInformation.NetworkInterface nic in System.Net.NetworkInformation.NetworkInterface .GetAllNetworkInterfaces())
{

if (nic.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up& &(!nic.Description.Contains( Virtual)&&!nic.Description .Contains( Pseudo)))
{
if (nic.GetPhysicalAddress()。ToString()!=
{
macID = nic.GetPhysicalAddress()。ToString();
}
}
}
返回 macID;
}



请帮帮我

解决方案

我写了一篇关于类似的东西可以帮助你:



指纹类 [ ^ ]

Hi All
I am trying to get unique Id of client machine but firewall of network not allowing me to get that I have tried for IP,MACID,Processor ID and also Mother Board ID but all are giving me server specific value of network not client machine.
Please let me know if any one idea for same.

using following code

private void UpdateOnlineUsers()
 {

     int userId = Convert.ToInt32(Session["userId"].ToString());
     //string clientIp = (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? Request.ServerVariables["REMOTE_ADDR"]).Split(',')[0].Trim();
     string clientIp = string.Concat(GetMaccID(), cpuId());
     user.UpdateOnlineUsers(userId, clientIp, false);
 }
 //Return a hardware identifier
 private static string identifier(string wmiClass, string wmiProperty)
 {
     string result = "";
     System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
     System.Management.ManagementObjectCollection moc = mc.GetInstances();
     foreach (System.Management.ManagementObject mo in moc)
     {
         //Only get the first one
         if (result == "")
         {
             try
             {
                 result = mo[wmiProperty].ToString();
                 break;
             }
             catch
             {
             }
         }
     }
     return result;
 }
 private static string cpuId()
 {
     //Uses first CPU identifier available in order of preference
     //Don't get all identifiers, as it is very time consuming
     string retVal = identifier("Win32_Processor", "UniqueId");
     if (retVal == "") //If no UniqueID, use ProcessorID
     {
         retVal = identifier("Win32_Processor", "ProcessorId");
         if (retVal == "") //If no ProcessorId, use Name
         {
             retVal = identifier("Win32_Processor", "Name");
             if (retVal == "") //If no Name, use Manufacturer
             {
                 retVal = identifier("Win32_Processor", "Manufacturer");
             }
             //Add clock speed for extra security
             retVal += identifier("Win32_Processor", "MaxClockSpeed");
         }
     }
     return retVal;
 }
 //Motherboard ID
 private static string baseId()
 {
     return identifier("Win32_BaseBoard", "Model")
     + identifier("Win32_BaseBoard", "Manufacturer")
     + identifier("Win32_BaseBoard", "Name")
     + identifier("Win32_BaseBoard", "SerialNumber");
 }
 private string GetMaccID()
 {
     string macID = string.Empty;
     foreach (System.Net.NetworkInformation.NetworkInterface nic in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
     {

         if (nic.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up && (!nic.Description.Contains("Virtual") && !nic.Description.Contains("Pseudo")))
         {
             if (nic.GetPhysicalAddress().ToString() != "")
             {
                 macID = nic.GetPhysicalAddress().ToString();
             }
         }
     }
     return macID;
 }


Please help me out

解决方案

I wrote an article about something similar that might help you along:

Finger Print Class[^]


这篇关于获取唯一客户端ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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