Solved

How to get MAC Address in Script

Posted on 2003-10-26
6
7,520 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 32

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 32

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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 viewer will learn how to dynamically set the form action using jQuery.

706 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

15 Experts available now in Live!

Get 1:1 Help Now