<summary>////This class is used to obtain the device's IP and Mac////</summary> public class Mac {[DllImport ("Iphlpapi.d LL ")] private static extern int Sendarp (Int32 dest, Int32 host, ref Int64 Mac, ref Int32 length); [DllImport ("Ws2_32.dll")] private static extern Int32 inet_addr (string IP); Gets the native IP public string getlocalip () {String strhostname = Dns.gethostname ();//Gets the host name of the native Iphostentry ipentry = Dns.gethostentry (strhostname); Gets the native IP string straddr = ipentry.addresslist[0]. ToString (); return (STRADDR); }//Get native Mac public string Getlocalmac () {string mac = null; ManagementObjectSearcher query = new ManagementObjectSearcher ("SELECT * from Win32_NetworkAdapterConfiguration"); Managementobjectcollection querycollection = query. Get (); foreach (ManagementObject mo in querycollection) {if (mo["IPEnAbled "]. ToString () = = "True") mac = mo["MacAddress"]. ToString (); } return (MAC); } }
C # get the IP and Mac classes for your device