
下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
using System.Net;using System.Net.networkinformation;/// <summary>/// Holds utilitIEs for working with networks,Ethernet,etc./// </summary>public static class NetworkUtils{ // http://www.codeproject.com/KB/IP/host_info_within_network.aspx [System.Runtime.InteropServices.Dllimport("iphlpAPI.dll",ExactSpelling = true)] static extern int SendARP(int DestIP,int SrcIP,byte[] pMacAddr,ref int PhyAddrLen); /// <summary> /// Gets the MAC address (<see cref="PhysicalAddress"/>) associated with the specifIEd IP. /// </summary> /// <param name="ipAddress">The remote IP address.</param> /// <returns>The remote machine's MAC address.</returns> public static PhysicalAddress GetMacAddress(IPAddress ipAddress) { const int MacAddressLength = 6; int length = MacAddressLength; var macBytes = new byte[MacAddressLength]; SendARP(BitConverter.ToInt32(ipAddress.GetAddressBytes(),0),macBytes,ref length); return new PhysicalAddress(macBytes); }}[TestClass()]public class NetworkUtilsTests{ [TestMethod()] public voID GetMacAddress_broadcastIP_NonzeroMac() { IPAddress ipAddress = IPAddress.broadcast; PhysicalAddress actual = NetworkUtils.GetMacAddress (ipAddress); Console.Writeline(actual.ToString()); Assert.AreNotEqual(PhysicalAddress.None,actual); }} 以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的C# 在指定的IP地址中获得一个设备的MAC(物理)地址全部内容,希望文章能够帮你解决C# 在指定的IP地址中获得一个设备的MAC(物理)地址所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)