Home > DeveloperSection > Blogs > Retriving network device information in c#.

Retriving network device information in c#.


C# C# 
Ratings:
0 Comment(s)
 9654  View(s)
Rate this:

In this blog I am demonstrating you that how to retrieve basic network device information such as network id, network name and description using c#.

To make this program you need to import  System.Net.NetworkInformation namespace.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Net.NetworkInformation;

namespace NetworkInformationDemo1

{

    class Program

    {

        static void Main(string[] args)

        {

            //Retrive all network interface using GetAllNetworkInterface() method off NetworkInterface class.

            NetworkInterface [] niArr = NetworkInterface.GetAllNetworkInterfaces();

            Console.WriteLine("Retriving basic information of network.\n\n");

            //Display all information of NetworkInterface using foreach loop.

            foreach(NetworkInterface tempNetworkInterface in niArr)

            {

                Console.WriteLine("Network Discription  :  " + tempNetworkInterface.Description);

                Console.WriteLine("Network ID  :  " + tempNetworkInterface.Id);

                Console.WriteLine("Network Name  :  " + tempNetworkInterface.Name);

                Console.WriteLine("Network interface type  :  " + tempNetworkInterface.NetworkInterfaceType.ToString());

                Console.WriteLine("Network Operational Status   :   " + tempNetworkInterface.OperationalStatus.ToString());

                Console.WriteLine("Network Spped   :   " + tempNetworkInterface.Speed);

                Console.WriteLine("Support Multicast   :   " + tempNetworkInterface.SupportsMulticast);

                Console.WriteLine();

            }

        }

    }

}

Output of the following code snippet is as follows:

Retriving basic information of network.

Network Discription  :  Realtek PCIe GBE Family Controller
Network ID  :  {80F43380-546G-44E2-B957-28ED63C5570C}
Network Name  :  Local Area Connection
Network interface type  :  Ethernet
Network Operational Status   :   Up
Network Spped   :   100000000
Support Multicast   :   True

Network Discription  :  Software Loopback Interface 1
Network ID  :  {846EE342-7039-11DE-9D20-8067039E6963}
Network Name  :  Loopback Pseudo-Interface 1
Network interface type  :  Loopback
Network Operational Status   :   Up
Network Spped   :   1073741824
Support Multicast   :   True

Network Discription  :  Microsoft ISATAP Adapter
Network ID  :  {8C7354CF-749A-40F5-8303-28ED63C5570C}
Network Name  :  isatap.local.lan
Network interface type  :  Tunnel
Network Operational Status   :   Down
Network Spped   :   100000
Support Multicast   :   False

Network Discription  :  Teredo Tunneling Pseudo-Interface
Network ID  :  {64BC6894-4D6D-4456-9B12-4D6D33032920}
Network Name  :  Local Area Connection* 9
Network interface type  :  Tunnel
Network Operational Status   :   Down
Network Spped   :   100000
Support Multicast   :   False


Don't want to miss updates? Please click the below button!

Follow MindStick