
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
920
|
Chapter 16: Networking
See Also
See the “Using SMTP for Outgoing Messages,” “SmtpMail Class,” “MailMessage
Class,” and “MailAttachment Class” topics in the MSDN documentation.
16.8 Check Out Your Network Connectivity
Problem
You need to determine the characteristics of the network adapters currently on the
machine.
Solution
Use the DisplayNICInfo method shown in Example 16-9 to display all of the charac-
teristics of the currently existing network adapters using the
System.Net.NetworkInformation.
NetworkInterface
class. Calling the GetAllNetworkInterfaces method will get the list
of current adapters as
NetworkInterface instances. Information such as the adapter
ID, MAC address, status, and NIC type is available on the
NetworkInterface class.
To see all of the IP information for an adapter, call the
GetIPProperties method on
the
NetworkAdapter instance and pass the IPInterfaceProperties collection to the
DisplayInterfaceProperties method (implemented shortly).
Example 16-9. DisplayNICInfo method
private static void DisplayNICInfo( )
{
//Display current network adapter states
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces( );
Console.WriteLine("Network Adapter Information:");
foreach (NetworkInterface n in adapters)
{
Console.WriteLine("\tId: {0}", n.Id);
Console.WriteLine("\tPhysical ...