The
looks up several methods and, after debugging, is a good way to get a local IP and MAC address. Can be used in this aspect of the functional implementation. The main is to add a system.management reference.
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 ();
}
}