Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have tried to get MAC address of each machine by using the below function in vb.net ,but I just realized that this function doesn't work in windows XP ,,


Function getMacAddress()
       Dim nics() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces()
       Return nics(1).GetPhysicalAddress.ToString
   End Function



can someone help me what should I do for solving in windows xp as well

Thanks in davnce
Posted

Could be you forgot the library

VB
Imports System.Net.NetworkInformation

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim mac As String
        mac = getMacAddress()
        MessageBox.Show(mac)
    End Sub

    Function getMacAddress()
        Dim nics() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces()
        Return nics(1).GetPhysicalAddress.ToString
    End Function

End Class
 
Share this answer
 
I think it does work in XP, I think the problem is that you are accessing the wrong array element:
Try:
VB
Return nics(0).GetPhysicalAddress.ToString
Or better still, loop through the array, and return the first one that is an ethernet adapter and operational.

There is a Tip here that shows the code - it's in C#, but the code is very easy to follow, look at the GetMacAddress method: Retrieving IP and MAC addresses for a LAN[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900