Sunday, June 17, 2012

How to get NIC Address or Machine Address in C# Programming using .NET technology

Step1: Add a refrence(System.Management) in Refrences Folder

Step2: use these "name space system" in code windows

using System.Management;
using System.Runtime.Remoting;
using System.Security.Permissions;
using System.Net.NetworkInformation;
using System.Collections;
using System.ComponentModel;

Step3: make a private function as GetMacAddress() and call it on an event;

private string GetMacAddressNew()
        {
            string macAddresses = "";

            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (nic.OperationalStatus == OperationalStatus.Up)
                {
                    macAddresses += nic.GetPhysicalAddress().ToString();
                    break;
                }
            }
            return macAddresses;
        }
That's it all.

No comments:

Post a Comment