?
Solved

VB.net Reliable way to always return the same code for the MACAddress

Posted on 2014-02-19
8
Medium Priority
?
208 Views
Last Modified: 2014-02-27
Hi

The following function always returned my machine's MAC addresss but suddenly returns a blank string. Why might the cause be?

    Friend Function GetMACAddress() As String

        Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
        Dim moc As ManagementObjectCollection = mc.GetInstances()
        Dim MACAddress As String = String.Empty
        For Each mo As ManagementObject In moc

            If (MACAddress.Equals(String.Empty)) Then
                If CBool(mo("IPEnabled")) Then MACAddress = mo("MacAddress").ToString()

                mo.Dispose()
            End If
            MACAddress = MACAddress.Replace(":", String.Empty)

        Next
        Return MACAddress
    End Function

Open in new window


The function below seems to work better but it said that that  only refers to the first network adapter
    Function getMacAddress()
        Dim nics() As NetworkInterface = _
              NetworkInterface.GetAllNetworkInterfaces
        Return nics(0).GetPhysicalAddress.ToString
    End Function

Open in new window



What is a reliable way to always return the same code for the MACAddress
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39870171
Problem with your first function is that it loops through the network adaptors and returns you MAC of the last adaptor in the loop. Problem with second function is that it always returns MAC of the first adaptor. What is your requirement? Always return the same MAC? Or always return some MAC?
0
 

Author Comment

by:Murray Brown
ID: 39870283
Hi
It is to always return the same MAC
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39870410
I don't know the context of your program but may be you run this function to get a valid MAC once and then store the MAC somewhere instead of calling this function every time.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Murray Brown
ID: 39879048
Hi
I am using the MAC address as a way to identify a valid user so it is stored in my cloud SQL
database. Each time the user connects my code validates that the MAC address is the same. So I am just looking for a way to return the same MAC address
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 39885332
One option then is to get MAC addresses of all the physical NICs in user's computer and then if any of the MACs matches with the one that you have in your database then its a known user.
0
 

Author Closing Comment

by:Murray Brown
ID: 39893892
thanks very much
0
 

Author Comment

by:Murray Brown
ID: 39893898
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question