I Made Krisna's Times My Way to Write the Times

10Aug/110

Get All Local Network Interface Card (NIC) C# Source Code

Yeah, actually i'm back to blogger activities... This is the part of my next projects, M-NIC Projects. The goal is to get all information of our network interface card (NIC) information such as IP addresses, link speed, name, etc. So after doing some head-to-head within some programming languages, my choices is C# .NET, because i think it's easiest way to get that. The result is something like below, i retrieve all of my NIC which status is UP

Name            : Wireless Network Connection 2
Type            : Wireless80211
Status          : Up
Speed           : 4294967295
Description     : Microsoft Virtual WiFi Miniport Adapter
InterNetworkV6  : fe80::e1cf:b2ee:f5c7:e23e%31
InterNetwork    : 192.168.2.1
=======================================
Name            : Local Area Connection
Type            : Ethernet
Status          : Up
Speed           : 100000000
Description     : Atheros AR8152 PCI-E Fast Ethernet Controller
InterNetwork    : 192.168.1.3
=======================================
Name            : Loopback Pseudo-Interface 1
Type            : Loopback
Status          : Up
Speed           : 1073741824
Description     : Software Loopback Interface 1
InterNetworkV6  : ::1
InterNetwork    : 127.0.0.1
=======================================

And here is the code:

static void Main(string[] args)
{
    NetworkInterface[] ifaceList = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface iface in ifaceList)
    {
        if (iface.OperationalStatus == OperationalStatus.Up)
        {
            Console.WriteLine("Name\t\t: " + iface.Name);
            Console.WriteLine("Type\t\t: " + iface.NetworkInterfaceType);
            Console.WriteLine("Status\t\t: " + iface.OperationalStatus);
            Console.WriteLine("Speed\t\t: " + iface.Speed);
            Console.WriteLine("Description\t: " + iface.Description);

            UnicastIPAddressInformationCollection unicastIPC = iface.GetIPProperties().UnicastAddresses;
            foreach (UnicastIPAddressInformation unicast in unicastIPC)
            {
                Console.WriteLine(unicast.Address.AddressFamily + "\t: " + unicast.Address);
            }
            Console.WriteLine("=======================================");
        }
    }
    Console.ReadKey();
}

Related posts:

  1. Simple HTTP Proxy Server C# Source Code
  2. Rail-Fence Cipher C# Source Code
  3. Fixing Network Problems Ubuntu 10.04 on Dell Inspiron 14R N4010
  4. Hello World MPI C Source Code
  5. Matrix-Vector Multiplication MPI C Source Code
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.