我需要使用asp.net的客户端机器的MAC地址 [英] i need MAC Address of client machine using asp.net
本文介绍了我需要使用asp.net的客户端机器的MAC地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨frnds
i需要使用asp.net
hi frnds
i need MAC Address of client machine using asp.net
推荐答案
protected void Page_Load(object sender, EventArgs e)
{
string macid= GetMacAddress("pass IP Address of the mechine");
}
[DllImport("iphlpapi.dll", ExactSpelling = true)]
public static extern int SendARP(int DestIP, int SrcIP, [Out] byte[] pMacAddr, ref int PhyAddrLen);
public string GetMacAddress(string sName)
{
string s = string.Empty;
System.Net.IPHostEntry Tempaddr = null;
Tempaddr = (System.Net.IPHostEntry)Dns.GetHostEntry(sName);
System.Net.IPAddress[] TempAd = Tempaddr.AddressList;
string[] Ipaddr = new string[3];
foreach (IPAddress TempA in TempAd)
{
Ipaddr[1] = TempA.ToString();
byte[] ab = new byte[6];
int len = ab.Length;
int r = SendARP((int)TempA.Address, 0, ab, ref len);
string sMAC = BitConverter.ToString(ab, 0, 6);
Ipaddr[2] = sMAC;
s = sMAC;
}
return s;
}
namespace: using System.Management;
string id=" ";
ManagementObjectSearcher query = null;
ManagementObjectCollection queryCollection = null;
try
{
query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
queryCollection = query.Get();
foreach (ManagementObject mo in queryCollection)
{
if (mo["MacAddress"] != null)
{
id = mo["MacAddress"].ToString();
MessageBox.Show(id);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Source);
MessageBox.Show(ex.Message);
}
GetMacAdress方法,不使用System.Management
GetMacAdress method without using System.Management
private string GetMAC()
{
string macAddresses = "";
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up)
{
macAddresses += nic.GetPhysicalAddress().ToString();
break;
}
}
return macAddresses;
}
这篇关于我需要使用asp.net的客户端机器的MAC地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文