MSDN.WhiteKnight - Stack Overflow answers
Ответ на "Узнавание мак адреса компьютера в локальной сети с помощью программных методов"
Answer 887571
Как вариант, можно получить MAC-адрес с помощью функции SendARP:
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Net; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class Program { [DllImport("iphlpapi.dll", ExactSpelling = true)] public static extern int SendARP(int DestIP, int SrcIP, [Out] byte[] pMacAddr, ref int PhyAddrLen); public static string GetMacByIp(IPAddress ip) { byte[] ab = new byte[6]; int len = ab.Length; int r = SendARP((int)ip.Address, 0, ab, ref len); if (r != 0) throw new ApplicationException("SendARP failed with code " + r.ToString()); return BitConverter.ToString(ab, 0, 6); } static void Main(string[] args) { IPAddress ip = IPAddress.Parse("192.168.0.1"); Console.WriteLine(GetMacByIp(ip)); Console.ReadKey(); } } }
Content is retrieved from StackExchange API.
Auto-generated by ruso-archive tools.