Thursday, May 28, 2009

Get Network Information in C#

public static string DisplayNICInfo()
{
//Display current network adapter states
StringBuilder sb= new StringBuilder();
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
sb.Append("Network Adapter Information:");
foreach (NetworkInterface n in adapters)
{
sb.Append(string.Format("\tId: {0}", n.Id));
sb.Append(string.Format("\tPhysical (MAC) Address: {0}",
n.GetPhysicalAddress().ToString()));
sb.Append(string.Format("\tDescription: {0}", n.Description));
sb.Append(string.Format("\tName: {0}", n.Name));
sb.Append(string.Format("\tOperationalStatus: {0}",
n.OperationalStatus.ToString()));
sb.Append(string.Format("\tInterface type: {0}",
n.NetworkInterfaceType.ToString()));
sb.Append(string.Format("\tSpeed: {0}", n.Speed));
//IPInterfaceProperties ipProps = n.GetIPProperties();
//DisplayInterfaceProperties(ipProps);
}
return sb.ToString();
}

No comments:

Post a Comment

 
Locations of visitors to this page