C#获取远程MAC地址
以下是我网上找的代码能得到同一段IP地址的MAC地址但是不是同一段的就不能得到
我只是需要内网
string userip = Request.UserHostAddress;
string strClientIP = Request.UserHostAddress.ToString().Trim();
Int32 ldest = inet_addr(strClientIP); //目的地的ip
Int32 lhost = inet_addr(""); //本地服务器的ip
Int64 macinfo = new Int64();
Int32 len = 6;
int res = SendARP(ldest, 0, ref macinfo, ref len);
string mac_src = macinfo.ToString("X");
if (mac_src == "0")
{
if (userip == "127.0.0.1")
Label1.Text="正在访问Localhost!";
else
Response.Write("欢迎来自IP为" + userip + "的朋友!" + "<br>");
return;
}
while (mac_src.Length < 12)
{
mac_src = mac_src.Insert(0, "0");
}
string mac_dest = "";
for (int i = 0; i < 11; i++)
{
if (0 == (i % 2))
{
if (i == 10)
{
mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2));
}
else
{
mac_dest = "-" + mac_dest.Insert(0, mac_src.Substring(i, 2));
}
}
}
Mac , C#
[解决办法]
局域网的应该可以获取到
http://download.csdn.net/detail/WUNEN/3343734#comment
[解决办法]
我没听说过。如果有这个,还要搞IP技术吗?
[解决办法]
public string GetMac(string clientIp)
{
string mac = "";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "nbtstat";
process.StartInfo.Arguments = "-a " + clientIp;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
string output = process.StandardOutput.ReadToEnd();
int length = output.IndexOf("MAC Address =");
if (length > 0)
{
mac = output.Substring(length + 14, 17);
}
return mac;
}