I found several methods. After debugging and modification, the following method can be used to obtain the local IP address and MAC address. It can be used to implement this function. It is mainly used to add a reference to system. Management.
Using system; using system. management; using system. net; public class program {static void main (string [] ARGs) {try {string IP = ""; string MAC = ""; managementclass MC; string hostinfo = DNS. gethostname (); // ip address // system. net. IPaddress [] Addresslist = DNS. gethostbyname (DNS. gethostname ()). addresslist; this obsolete system. net. IPaddress [] Addresslist = DNS. gethostentry (DNS. gethostname ()). addresslist; For (INT I = 0; I <Addresslist. length; I ++) {IP = Addresslist [I]. tostring ();} // MAC address MC = new managementclass ("win32_networkadapterconfiguration"); managementobjectcollection MOC = MC. getinstances (); foreach (managementobject Mo in MoC) {If (Mo ["ipenabled"]. tostring () = "true") {MAC = Mo ["macaddress"]. tostring () ;}// output string outputstr = "IP: {0}, \ n MAC address: {1}"; outputstr = string. format (outputstr, IP, Mac); console. writeline (outputstr);} catch (exception e) {} console. readline ();}}