为什么用SendARP获取局域网的网卡的MAC地址只返回前4位???而不是6位呢?
可以得到全段的值吗??
可以得到全段的值吗??
解决方案 »
- 自己做的DLL组件用不了
- 想搞本证书,不知道搞哪种好
- ◆关于批量下载程序◆
- Visual Studio 2003的水晶报表如何设置纸张大小?
- 请问一下在C#里有没有处理二进制的函数,,如果没有可唔可以提供下处理方法??
- 如何在程序运行中动态改变对象属性在PropertyGrid中显示出来的只读性(100分求助)
- 我的Log4net为什么没能产生log文件?
- 谁知道有哪个比较出名的网站是用.net做的吗?
- 三层中的事务处理应该放在逻辑层处理么?
- 如何使程序只能有一个在运行?
- 关于自定义控件的属性问题,困挠很久了,恳请高手帮忙解决!
- 基于windows的程序启动IE后,和IE交互的问题(谢绝灌水!)。
public static string GetMac()
{
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");
System.Management.ManagementObjectCollection moc = mc.GetInstances();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach(ManagementObject mo in moc)
{
if((bool)mo["IPEnabled"] == true)
sb.Append(mo["MacAddress"].ToString());
mo.Dispose();
}
return(sb.ToString());
}
你没贴出你的代码, 不知道是否是你的代码有问题, 看看上面两个联结
private string getRemoteMAC(string localIP, string remoteIP)
{
Int32 ldest= inet_addr(remoteIP); //目的地的ip
Int32 lhost= inet_addr(localIP); //本地服务器的ip try
{
Byte[] macinfo=new Byte[6];
Int32 length=6;
IntPtr mac=new IntPtr(macinfo[0]);
IntPtr len=new IntPtr(6);
int ii=SendARP(ldest,lhost, ref mac, ref len);
return mac.ToString();
}
catch(Exception err)
{
return string.Empty;
}
return string.Empty;
}可以得到数转换为16进制时,只有前4位
例如:
01-22-23-24-25-26
我只能得到01222324
不能得到全部.
public static extern int SendARP( Int32 DestIP, Int32 SrcIP,[Out] byte[] pMacAddr, ref IntPtr PhyAddrLen );int ii=SendARP(ldest, lhost, macinfo, ref len);
public static extern int SendARP (Int32 dest,Int32 host,ref Int64 mac,ref Int32 length);//dest为目标机器的IP;Host为本机器的IP [DllImport("Ws2_32.dll")]
public static extern Int32 inet_addr (string ip);IPHostEntry myiphost=Dns.GetHostByName(System.Environment.MachineName);
IPAddress []myip=myiphost.AddressList;
this.textBox3.Text=myip[0].ToString();
Int32 mysource=inet_addr(this.textBox3.Text.Trim());//本地IP
Int32 iptest=inet_addr(myip);//目标IP
Int64 macinfo=new Int64();
Int32 len=6; string z;
SendARP(iptest,mysource,ref macinfo,ref len);
z=System.Convert.ToString(macinfo,16);