C SharP中,获得了客户端的IP后,该如何获取其MAC地址 C SharP中,获得了客户端的IP后,该如何获取其MAC地址谢谢~~~~~~~~~~~~~~~~~~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是在server端获取client端的mac地址,还是client端获取本机的mac地址如果是后者,可以参看http://www.codeproject.com/csharp/host_info_within_network.asp 前者是不可能的,除非client端告知。 哦!!我是想获取Client端的MAC地址!真的不行啊,我想是否可由IP地址映射到其MAC地址~~~~~~~~~~那该如何获取其Mac,难道要分析其帧,是否太麻烦了??? to 真的不行啊,我想是否可由IP地址映射到其MAC地址不可能,除非你服务器有IP与Mac之间的对应关系。 IP包头中包括客户端的 Mac 地址,具体可参见 IP 头结构 可以获取MAC吧。有一款软件“网络剪刀手"NetCut可以获取局域网所有电脑的MAC 用这个去获取,没问题.nbtstat -A xxx.xxx.xxx.xxx 还可用这个API函数.[DllImport("Iphlpapi.dll")] private static extern int SendARP(Int32 dest,Int32 host,ref Int64 mac,ref Int32 length); 我没找到这个API函数,可否帮我解释一下函数的参数,及其返回值谢谢~~~~~~~~~ 参见:http://spaces.msn.com/cloudhuhu/Blog/cns!1pGWJrG_igtoCGSKMmhnpk-g!116.entry使用SendARP获取MAC using System.Runtime.InteropServices;using System.Text.RegularExpressions;using System.Text; [DllImport("Iphlpapi.dll")]private static unsafe extern int SendARP(Int32 dest,Int32 host,ref Int32 mac,ref Int32 length);[DllImport("Ws2_32.dll")]private static extern Int32 inet_addr(string ip);public string GetMACFromIP(string A_strIP){ string strRet = "Unknown"; string strIPPattern = @"^\d+\.\d+\.\d+\.\d+$"; Regex objRex =new Regex(strIPPattern); if(objRex.IsMatch(A_strIP) == true) { Int32 intDest = inet_addr(A_strIP); Int32 [] arrMAC = new Int32[2]; Int32 intLen = 6; int intResult = SendARP(intDest,0,ref arrMAC[0],ref intLen); if(intResult == 0) { Byte [] arrbyte = new Byte[8]; arrbyte[5] = (Byte)(arrMAC[1] >> 8); arrbyte[4] = (Byte)arrMAC[1]; arrbyte[3] = (Byte)(arrMAC[0] >> 24); arrbyte[2] = (Byte)(arrMAC[0] >> 16); arrbyte[1] = (Byte)(arrMAC[0] >> 8); arrbyte[0] = (Byte)arrMAC[0]; StringBuilder strbMAC = new StringBuilder(); for(int intIndex = 0 ;intIndex < 6;intIndex ++) { if(intIndex > 0) strbMAC.Append("-"); strbMAC.Append(arrbyte[intIndex].ToString("X2")); } strRet = strbMAC.ToString(); } }return strRet;} 局域网里面的机器可以获得MAC公网的基本别想了,路由器不会转发这些数据的 public static 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; } try:Process p = new Process();p.StartInfo.FileName = "cmd.exe";p.StartInfo.UseShellExecute = false;p.StartInfo.RedirectStandardInput = true;p.StartInfo.RedirectStandardOutput = true;p.Start();p.StandardInput.WriteLine("nbtstat -A 192.168.xx.xx");p.StandardInput.WriteLine("exit");string s = "";while((s = p.StandardOutput.ReadLine()) != null){ if(s.Contains("MAC")) { Console.WriteLine(s); }} insiderc() 强~感谢 求 C# 抽奖程序 求助,控件改名的bug。。。 文件下载 请问如何将SQLite数据库的表结构及其数据复制到MSSQLerver数据库中去呢? 地区联动菜单 又开始找工作了,说点找工作的事情,请过来人给点建议。 请各路高手帮忙进来看一下,急了一下午的问题~~~~~~~~~~~~~~ C#如何实现将outlook邮件导出至excel表中。 请问如何将.net生成的xml项目文档文件转换成html格式 安装后自动登录,如何修改密码? 关于进销存系统一点不懂想做 十万火急,再次提问!SQL联接多表的问题!
http://www.codeproject.com/csharp/host_info_within_network.asp
我是想获取Client端的MAC地址!
真的不行啊,我想是否可由IP地址映射到其MAC地址~~~~~~~~~~
那该如何获取其Mac,难道要分析其帧,是否太麻烦了???
nbtstat -A xxx.xxx.xxx.xxx
private static extern int SendARP(Int32 dest,Int32 host,ref Int64 mac,ref Int32 length);
谢谢~~~~~~~~~
using System.Text.RegularExpressions;
using System.Text;
[DllImport("Iphlpapi.dll")]
private static unsafe extern int SendARP(Int32 dest,Int32 host,ref Int32 mac,ref Int32 length);[DllImport("Ws2_32.dll")]
private static extern Int32 inet_addr(string ip);public string GetMACFromIP(string A_strIP)
{
string strRet = "Unknown";
string strIPPattern = @"^\d+\.\d+\.\d+\.\d+$"; Regex objRex =new Regex(strIPPattern);
if(objRex.IsMatch(A_strIP) == true)
{
Int32 intDest = inet_addr(A_strIP);
Int32 [] arrMAC = new Int32[2];
Int32 intLen = 6;
int intResult = SendARP(intDest,0,ref arrMAC[0],ref intLen);
if(intResult == 0)
{
Byte [] arrbyte = new Byte[8];
arrbyte[5] = (Byte)(arrMAC[1] >> 8);
arrbyte[4] = (Byte)arrMAC[1];
arrbyte[3] = (Byte)(arrMAC[0] >> 24);
arrbyte[2] = (Byte)(arrMAC[0] >> 16);
arrbyte[1] = (Byte)(arrMAC[0] >> 8);
arrbyte[0] = (Byte)arrMAC[0]; StringBuilder strbMAC = new StringBuilder();
for(int intIndex = 0 ;intIndex < 6;intIndex ++)
{
if(intIndex > 0) strbMAC.Append("-");
strbMAC.Append(arrbyte[intIndex].ToString("X2"));
}
strRet = strbMAC.ToString();
}
}return strRet;
}
公网的基本别想了,路由器不会转发这些数据的
{
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;
}
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;p.Start();
p.StandardInput.WriteLine("nbtstat -A 192.168.xx.xx");
p.StandardInput.WriteLine("exit");string s = "";while((s = p.StandardOutput.ReadLine()) != null)
{
if(s.Contains("MAC"))
{
Console.WriteLine(s);
}
}
强~
感谢