A MAC (Media Access Control) address is a number that identifies the network adapter(s) installed on your computer. The address is composed of up to 6 pairs of characters, separated by colons. You may need to provide your MAC address to a router in order to successfully connect to a network. There are so many ways to find the MAC Address of your PC. But in this article, we will only locate and know what is our IP address and then we can know also our MAC Address.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File
, click New Project
, and choose Windows Application
2. Next, add only one Button named Button1
and labeled it as "Get MAC Address
". Insert two textboxes named Textbox1
for inputting the IP Address and Textbox2
for displaying the MAC Address. You must design your interface like this:
3. Now put this code for your code module.
Public Class Form1
Private Declare Function inet_addr Lib "wsock32.dll" (ByVal s As String) As Integer
Private Declare Function SendARP Lib "iphlpapi.dll" (ByVal DestIP As Integer, ByVal SrcIP As Integer, ByRef pMACAddr As Integer, ByRef PhyAddrLen As Integer) As Integer
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef dst As Byte, ByRef src As Integer, ByVal bcount As Integer)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sip As String
Dim inet As Integer
Dim b(6) As Byte
Dim pMACAddr As Integer
Dim i As Short
Dim sResult As String = ""
sip = TextBox1.Text
inet = inet_addr(sIP)
If SendARP(inet, 0, pMACAddr, 6) = 0 Then
CopyMemory(b(0), pMACAddr, 6)
For i = 0 To 5
Microsoft.VisualBasic.Right("0" & Hex(
If i < 5 Then sResult &= "-"
TextBox2.Text = sResult
We declare first the library function of wsock32.dll named inet_addr
. wsock32.dll is for winsock/windows socket creates a socket that is bound to a specific transport service provider. It also enables programmers to create advanced Internet, intranet, and other network-capable applications to transmit application data across the wire, independent of the network protocol being used. Next is the SendARP that has the library of iphlpapi.dll. The SendARP function
sends an Address Resolution Protocol (ARP) request to obtain the physical address that corresponds to the specified destination IPv4 address. Last is the Copy Memory
function which copies a block of memory from one location to another and is on the library of kernel32. sIP variable holds the IP address iputted in textbox1. Then the inet which holds the socket will also hold the value in textbox1. If
SendARP(inet, 0, pMACAddr, 6) = 0
= Destination IP, 0
= Source IP, pMACAddr = Present MAC Address, and 6
= Physical Address Length, then the value of it will be copied and held now by CopyMemory function. There are 6 pairs of characters in a MAC address so we have created a for loop which starts to 0 up to 5 in which all the value of the MAC Address is held by sResult and will be displayed in Textbox2.
Download the source code below and try it! :)
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below and hire me.
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Visit and like my page on Facebook at: Bermz ISware Solutions
Subscribe at my YouTube Channel at: SerBermz
Visit my website at: CampCodes