Solved

How to get MAC Address in Script

Posted on 2003-10-26
6
7,534 Views
Last Modified: 2007-12-19
How to get MAC Address in JavaScript or VBScript. Also provide solution if there are two network cards in one system.
0
Comment
Question by:nabilpk
  • 2
6 Comments
 
LVL 33

Expert Comment

by:shalomc
ID: 9625858
nabilpk,
You will have to write an ActiveX component and the user will have to agree to it running on the user's PC.

ShalomC
0
 
LVL 2

Accepted Solution

by:
hb21l6 earned 20 total points
ID: 9626569
I use this and this works fine over LAN!!! I have not tested over the net.... (ASP)

<%@ LANGUAGE="VBSCRIPT"%>
    <%
          strIP = Request.ServerVariables("REMOTE_ADDR")
          strMac = GetMACAddress(strIP)
          strHost = Request.ServerVariables("REMOTE_HOST")
    function GetMACAddress(strIP)
    Set net = Server.CreateObject("wscript.network")
    Set sh = Server.CreateObject("wscript.shell")
    sh.run "%comspec% /c nbtstat -A " & strIP & " > c:\" & strIP & ".txt",0,true
    Set sh = nothing
    Set fso = createobject("scripting.filesystemobject")
    Set ts = fso.opentextfile("c:\" & strIP & ".txt")
    macaddress = null
    Do While Not ts.AtEndOfStream
    data = ucase(trim(ts.readline))
    if instr(data,"MAC ADDRESS") Then
    macaddress = trim(split(data,"=")(1))
    Exit Do
    End if
    loop
    ts.close
    Set ts = nothing
    fso.deletefile "c:\" & strIP & ".txt"
    Set fso = nothing
    GetMACAddress = macaddress
    End function      
   
   
    yourIP = strIP
    yourMAC = strMac

if yourIP = "" Then
yourIP = 00
end if


if yourMAC = "" Then
yourMAC = 00
end if

   
%>

let use know if it works.. thanks

hb
0
 
LVL 33

Expert Comment

by:shalomc
ID: 9627936
hb21l6 ,
That is a nice script.
It may do the job, but there are prerequisites:
The server must run IIS, the client must have NetBios enabled, no firewall can be between client and server.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

820 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