: Get MAC address of system | ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial : Get MAC address of system

In this article I am going to explain how to get MAC address of system using

MAC (Media access control) address is the unique identifier of each device. To know MAC address go to command prompt and type ipconfig/all, hit the enter button. : Get MAC address of system

 HTML Markup:
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:Button ID="btnsubmit" runat="server" Text="Get MAC Address"/>

        <br />
        <asp:Label ID="lblname" runat="server" Text="Label" Visible="false"></asp:Label>

Add namespace
C# Code:
using System.Net.NetworkInformation; Code:
Imports System.Net.NetworkInformation

On button click write the below given code:

C# Code:
string amacaddress = "";

    protected void btnsubmit_Click(object sender, EventArgs e)
            NetworkInterface[] anics = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in anics)
                if (amacaddress == String.Empty)
                    IPInterfaceProperties properties = adapter.GetIPProperties();
                    amacaddress = adapter.GetPhysicalAddress().ToString();
                    lblname.Visible = true;
                    lblname.Text = "MAC Address is :- " + amacaddress;
        catch (Exception ex) { }      
    } Code:
    Dim amacaddress As String
    Protected Sub btnsubmit_Click(sender As Object, e As EventArgs) Handles btnsubmit.Click
            Dim anics As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
            For Each adapter As NetworkInterface In anics
                If amacaddress = [String].Empty Then
                    Dim properties As IPInterfaceProperties = adapter.GetIPProperties()
                    amacaddress = adapter.GetPhysicalAddress().ToString()
                    lblname.Visible = True
                    lblname.Text = "MAC Address is :- " + amacaddress
                End If
        Catch ex As Exception
        End Try
    End Sub
End Class

Post a Comment



Contact Form


Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget