Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get Client  Mac Address

Posted on 2003-12-09
11
Medium Priority
?
5,933 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
[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
11 Comments
 
LVL 17

Accepted Solution

by:
Tacobell777 earned 1000 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
URL rewriting in AWS CloudFront

A quick how-to guide to implement with a Lambda function!

 
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
 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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