Solved

Get Client  Mac Address

Posted on 2003-12-09
11
5,890 Views
Last Modified: 2012-08-13
Hi

My problem is that I need to get the NIC mac address off of the client's laptop for successful registration across our network.

I am using .NET to write the application, but assume that I need to host the script client-side or else I invariably get the mac address off of my server!

Is there a way to do this using Javascript?  If not, how could I detect this info using server-side scripting?

Thanks,

Tom

0
Comment
Question by:trman
11 Comments
 
LVL 17

Accepted Solution

by:
Tacobell777 earned 250 total points
ID: 9909482
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2003 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce
'               or publish this code on any web site,
'               online service, or distribute as source
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Const NO_ERROR = 0

Private Declare Function inet_addr Lib "wsock32.dll" _
  (ByVal s As String) As Long

Private Declare Function SendARP Lib "iphlpapi.dll" _
  (ByVal DestIP As Long, _
   ByVal SrcIP As Long, _
   pMacAddr As Long, _
   PhyAddrLen As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" _
   Alias "RtlMoveMemory" _
  (dst As Any, _
   src As Any, _
   ByVal bcount As Long)
   


Private Sub Form_Load()

   Text1.Text = "192.168.1.101"
   Text2.Text = ""
   Command1.Caption = "Get Remote Mac Address"
   
End Sub


Private Sub Command1_Click()

   Dim sRemoteMacAddress As String
   
   If Len(Text1.Text) > 0 Then
   
      If GetRemoteMACAddress(Text1.Text, sRemoteMacAddress) Then
         Text2.Text = sRemoteMacAddress
      Else
         Text2.Text = "(SendARP call failed)"
      End If
     
   End If

End Sub


Private Function GetRemoteMACAddress(ByVal sRemoteIP As String, _
                                     sRemoteMacAddress As String) As Boolean

   Dim dwRemoteIP As Long
   Dim pMacAddr As Long
   Dim bpMacAddr() As Byte
   Dim PhyAddrLen As Long
   Dim cnt As Long
   Dim tmp As String
   
  'convert the string IP into
  'an unsigned long value containing
  'a suitable binary representation
  'of the Internet address given
   dwRemoteIP = inet_addr(sRemoteIP)
   
   If dwRemoteIP <> 0 Then
   
     'set PhyAddrLen to 6
      PhyAddrLen = 6
   
     'retrieve the remote MAC address
      If SendARP(dwRemoteIP, 0&, pMacAddr, PhyAddrLen) = NO_ERROR Then
     
         If pMacAddr <> 0 And PhyAddrLen <> 0 Then
     
           'returned value is a long pointer
           'to the mac address, so copy data
           'to a byte array
            ReDim bpMacAddr(0 To PhyAddrLen - 1)
            CopyMemory bpMacAddr(0), pMacAddr, ByVal PhyAddrLen
         
           'loop through array to build string
            For cnt = 0 To PhyAddrLen - 1
               
               If bpMacAddr(cnt) = 0 Then
                  tmp = tmp & "00-"
               Else
                  tmp = tmp & Hex$(bpMacAddr(cnt)) & "-"
               End If
         
            Next
           
           'remove the trailing dash
           'added above and return True
            If Len(tmp) > 0 Then
               sRemoteMacAddress = Left$(tmp, Len(tmp) - 1)
               GetRemoteMACAddress = True
            End If

            Exit Function
         
         Else
            GetRemoteMACAddress = False
         End If
           
      Else
         GetRemoteMACAddress = False
      End If  'SendARP
     
   Else
      GetRemoteMACAddress = False
   End If  'dwRemoteIP
     
End Function
'--end block--'
0
 
LVL 10

Expert Comment

by:Nushi
ID: 9910875
why not using a server side code to do it?
the client is connected to your side so simply run a few lines of code
(Java,PHP etc).

Nushi.
0
 

Author Comment

by:trman
ID: 9932870
Thx for your posts.

Tacobell, will this code return the remote user's NIC mac address or does it resolve the ip address only.

Nushi, what vb.net code do you suggest?

Tom
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 9932889
it should return the remote mac address

There are numerous ways of doing it, what server-side language are you using?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:trman
ID: 9933023
HI Tacobell,

I am using vb.net
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 9933068
then the above code should be familiar to you, correct?
0
 

Author Comment

by:trman
ID: 9933083
Yes, it is.  I just didn't see a reference to the 'Win32_NetworkAdapterConfiguration' Management Class which is what I am familiar with.

By the way, what part of the above code queries the calling machine's info?
0
 

Author Comment

by:trman
ID: 9939069
The above Function has build errors in VB.net and does not work.  Specifically, this line:   ReDim bpMacAddr(0 To PhyAddrLen - 1)
returns errors...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10246846
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: Tacobell777 {http:#9909482}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now