问题
In web project I have a Page which fetches the Local System Mac-id and other values such as processorid etc,for that I have used the below code.It worked perfectly during Development in the Localhost
but when we had published the website and now use the same page to fetch the details,it is fetching the details of the Web Server.Is there any alternate way to fetch the Local Machines details.Kindly any one help.
The code I ued for Fetching System details is,
#region Sytem Details
private string GetMac()
{
string Mac = string.Empty;
ManagementClass MC = new ManagementClass("Win32_NetworkAdapter");
ManagementObjectCollection MOCol = MC.GetInstances();
foreach (ManagementObject MO in MOCol)
if (MO != null)
{
if (MO["MacAddress"] != null)
{
Mac = MO["MACAddress"].ToString();
if (Mac != string.Empty)
break;
}
}
return Mac;
}
public static string LocalIPAddress()
{
IPHostEntry host;
string localIP = "";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily.ToString() == "InterNetwork")
{
localIP = ip.ToString();
}
}
return localIP;
}
private static string GetProcessorName()
{
ManagementClass mgt = new ManagementClass("Win32_Processor");
ManagementObjectCollection procs = mgt.GetInstances();
foreach (ManagementObject item in procs)
return item.Properties["Name"].Value.ToString();
return "Unknown";
}
private string GetProcessorID()
{
string sCpuInfo = String.Empty;
bool bSuccess = false;
//*** Declare Management Class
ManagementClass clsMgtClass = new ManagementClass("Win32_Processor");
ManagementObjectCollection colMgtObjCol = clsMgtClass.GetInstances();
//*** Loop Over Objects
foreach (ManagementObject objMgtObj in colMgtObjCol)
{
//*** Only return cpuInfo from first CPU
if (sCpuInfo == String.Empty)
{
sCpuInfo = objMgtObj.Properties["ProcessorId"].Value.ToString();
bSuccess = true;
}
}
if (bSuccess == true)
{
}
return sCpuInfo;
}
private static string GetName()
{
string netBiosName = System.Environment.MachineName;
//return netBiosName;
// Following method is deprecated
// string dnsName =
// System.Net.Dns.GetHostByName("LocalHost").HostName;
string dnsName = System.Net.Dns.GetHostName();
return dnsName;
}
private string GetOSName()
{
System.OperatingSystem os = System.Environment.OSVersion;
string osName = "Unknown";
switch (os.Platform)
{
case System.PlatformID.Win32Windows:
switch (os.Version.Minor)
{
case 0:
osName = "Windows 95";
break;
case 10:
osName = "Windows 98";
break;
case 90:
osName = "Windows ME";
break;
}
break;
case System.PlatformID.Win32NT:
switch (os.Version.Major)
{
case 3:
osName = "Windws NT 3.51";
break;
case 4:
osName = "Windows NT 4";
break;
case 5:
if (os.Version.Minor == 0)
osName = "Windows 2000";
else if (os.Version.Minor == 1)
osName = "Windows XP";
else if (os.Version.Minor == 2)
osName = "Windows Server 2003";
else if (os.Version.Minor == 3)
osName = "Windows Vista";
else if (os.Version.Minor == 4)
osName = "Windows 7";
break;
case 6:
osName = "Windows 8";
break;
}
break;
}
return osName;
}
#endregion
Edit
It may not be over the Internet because the User is going to register the System,so he/she only gets the details and registers,so is there any way of Automatically getting the users PC data from his end in Just a Click of a button.
回答1:
Over Internet you can't fetch Mac Address of client machine if the device/system comes after a router in Network, though if your application is an Intranet application you can first get the IP address of client and then apply an ARP to get the mac ID of client device/machine. I have done this for one of my projects to get the mac ID of client's device but I have used a DHCP read for the same.
来源:https://stackoverflow.com/questions/19245571/how-to-get-the-client-system-mac-id-and-other-details-like-ip-address-etc