C# socket获取对等方mac地址
private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
public static string getRemoteMac(string remoteIP)
{
var addr = IPAddress.Parse(remoteIP);
int ip4 = BitConverter.ToInt32((addr.GetAddressBytes()), 0);
try
{
long macinfo = 0;
int len = 6;
int res = SendARP(ip4, 0, ref macinfo, ref len);
return Convert.ToString(macinfo, 16);
}
catch (Exception err)
{
Console.WriteLine("Error:{0}", err.Message);
}
return 0.ToString();
}
static void Main(string[] args)
{
Console.WriteLine(getRemoteMac("192.168.0.150"));
Console.ReadLine();
}
注意这种方式,很多大公司都有不同的防火墙,这种方式用arp攻击来实现的,但是有的防火墙会屏蔽arp攻击,这种方式不是很稳定
页:
[1]