如何获取网卡物理地址
现在有公司内部有几台电脑,我想知道没台机器的物理地址怎么获取?
------解决方案-------------------- /// <summary>
/// 以下是获取网卡 MAC地址的方法.
/// 只能获取第一块
/// </summary>
/// <returns></returns>
public static string GetMacAddress()
{
ManagementClass adapters = new ManagementClass("Win32_NetworkAdapterConfiguration");
string MACAddress = "unknown";
foreach (ManagementObject adapter in adapters.GetInstances())
{
if((bool)adapter["IPEnabled"] == true)
{
MACAddress = adapter.Properties["MACAddress"].Value.ToString();
break;
}
}
return MACAddress;
}
------解决方案--------------------那就在客戶端的程序裡寫一個然發送回來保存在數據庫裡。
public string GetNetCard()
{
string str = "";
ManagementClass mcMAC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection mocMAC = mcMAC.GetInstances();
foreach (ManagementObject m in mocMAC)
{
if ((bool)m["IPEnabled"])
{
str = m["MacAddress"].ToString();
break;
}
}
return str;
}
------解决方案--------------------using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Management;
namespace POS
{
class GetVol
{
[DllImport("kernel32.dll")]
private static extern int GetVolumeInformation(
string lpRootPathName,
string lpVolumeNameBuffer,
int nVolumeNameSize,
ref int lpVolumeSerialNumber,
int lpMaximumComponentLength,
int lpFileSystemFlags,
string lpFileSystemNameBuffer,
int nFileSystemNameSize
);
public string GetVolOf(string drvID)
{
const int MAX_FILENAME_LEN = 256;
int retVal = 0;
int a = 0;
int b = 0;
string str1 = null;
string str2 = null;
int i = GetVolumeInformation(
drvID + @":\",
str1,
MAX_FILENAME_LEN,
ref retVal,
a,
b,
str2,
MAX_FILENAME_LEN
);
return retVal.ToString("x");
}
public string GetNetCard()
{
string str = "";
ManagementClass mcMAC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection mocMAC = mcMAC.GetInstances();
foreach (ManagementObject m in mocMAC)
{
if ((bool)m["IPEnabled"])
{
str = m["MacAddress"].ToString();
break;
}
}
return str;
}
}
}
------解决方案--------------------是不是想获取他们的物理地址,来加密,如果不是那些物理地址的机器就运行不了程序?
网卡的物理地址可能重复的也可以改!
本人感觉获取他的物理地址没有什么用哦加密的话!
------解决方案--------------------取硬盘的物理地址,然后加网卡的物理地址,同时加密比较安全点哈哈(不过硬盘的物理地址和网卡的都一样可以改)!
以前做过所以给点意见而已(路过)
------解决方案--------------------