一获取mac地址
1.先添加system.management的dll组件
2.添加引用
public string GetMACAddress()
{
string MoAddress = "";
ManagementObjectSearcher query = new ManagementObjectSearcher("select * from Win32_NetworkAdapterConfiguration");
ManagementObjectCollection querylist = query.Get();
foreach (ManagementObject mo in querylist)
{
if(mo["IPEnabled"].ToString() == "True")
{
MoAddress = mo["MacAddress"].ToString();
}
}
return MoAddress;
}
二获取登陆用户的IP地址
IPHostEntry oIPHost = Dns.Resolve(Environment.MachineName);
loginlogs.IP = oIPHost.AddressList[0].ToString();