private void button1_Click(object sender, EventArgs e) { labelIP.Text = DoGetHostAddresses(txtbHostName.Text).ToString(); labelMAC.Text = ConvertIpToMAC(DoGetHostAddresses(txtbHostName.Text)); } #region Get IP public static IPAddress DoGetHostAddresses(string hostname) { IPAddress[] ips; ips = Dns.GetHostAddresses(hostname); return ips[0]; } #endregion #region Get MAC [DllImport("iphlpapi.dll", ExactSpelling = true)] public static extern int SendARP(int DestIP, int SrcIP, [Out] byte[] pMacAddr, ref int PhyAddrLen); public static string ConvertIpToMAC(IPAddress ip) { byte[] ab = new byte[6]; int len = ab.Length; int r = SendARP(ip.GetHashCode(), 0, ab, ref len); return BitConverter.ToString(ab, 0, 6); } #endregion
Комментариев нет:
Отправить комментарий