C # get the IP and Mac classes for your device

Source: Internet
Author: User

 <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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.