jagu98
asked on
Get client MAC Address
I need to get the MAC address of the client machine when it navigates to a specific page on my WinNT Server running IIS. If anyone knows a script(ASP or Javascript preferred) or has another suggestion, please let me know.
I've tried creating an ActiveX dll in vb but no good.
I've tried creating an ActiveX dll in vb but no good.
another thought, is that I am sure with IIS you can get the ip address of the user, (I think it is Server.RequetsVariables("R EMOTE_ADDR "))
you could use something like wsh again but on the server side, but if there is a command line tool with changes an ip to a mac address, I don't know of one off teh top of my head but there must be something.
Ed
you could use something like wsh again but on the server side, but if there is a command line tool with changes an ip to a mac address, I don't know of one off teh top of my head but there must be something.
Ed
ASKER
I thank you Ginger Ed for your comments, but unfortunatly I need to code for Netscape or IE. One of the versions of the ActiveX dll I made actually did a shell out to an EXE I wrote using nbtstat -A "ip address" > at the command prompt and created an htm file with the information I need. It works great on the pc but when I call it from ASP... CRASH! Major mem leaks and it didn't create the htm file.
instead of creating a file use http://www.serverobjects.com/comp/Aspexec.zip to run something like arp to get the mac based on REMOTE_ADDR
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ginger Ed - I was successful earlier today and it just so happens that I did it the way you suggested on your last comment prior to viewing it. You pointed me in the right direction. I left the code at work but I'll make sure to post it here tomorrow along with giving you the credit of the points. Thanks again for pointing in the direction.
ASKER
A word of caution, if you test this on your own pc running PWS it will hang. NBTSTAT does not like 127.0.0.1. You can let it run on PWS and navigate to it from another pc and it will work fine.
<%@ LANGUAGE="VBSCRIPT"%>
<%
strIP = Request.ServerVariables("R EMOTE_ADDR ")
strMac = GetMACAddress(strIP)
strHost = Request.ServerVariables("R EMOTE_HOST ")
Function GetMACAddress(strIP)
set net = Server.CreateObject("wscri pt.network ")
set sh = Server.CreateObject("wscri pt.shell")
sh.run "%comspec% /c nbtstat -A " & strIP & " > c:\" & strIP & ".txt",0,true
set sh = nothing
set fso = createobject("scripting.fi lesystemob ject")
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
%>
<html>
<HEAD>
<TITLE>Say Hello To the MAC MAN</TITLE>
</HEAD>
<body>
<%Response.Write("Your IP is : " & strIP & "<br>" & vbcrlf)%>
<%Response.Write("Your MAC is : " & strMac & vbcrlf)%>
</body>
</html>
<%@ LANGUAGE="VBSCRIPT"%>
<%
strIP = Request.ServerVariables("R
strMac = GetMACAddress(strIP)
strHost = Request.ServerVariables("R
Function GetMACAddress(strIP)
set net = Server.CreateObject("wscri
set sh = Server.CreateObject("wscri
sh.run "%comspec% /c nbtstat -A " & strIP & " > c:\" & strIP & ".txt",0,true
set sh = nothing
set fso = createobject("scripting.fi
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
%>
<html>
<HEAD>
<TITLE>Say Hello To the MAC MAN</TITLE>
</HEAD>
<body>
<%Response.Write("Your IP is : " & strIP & "<br>" & vbcrlf)%>
<%Response.Write("Your MAC is : " & strMac & vbcrlf)%>
</body>
</html>
ASKER
Thanks again Ginger Ed
cool,
I just wanted to say:
"Hello Mac Man"
Ed
I just wanted to say:
"Hello Mac Man"
Ed
It does the joba nd gets all the mac address of the machine, but try it out:
<HTML>
<HEAD>
<SCRIPT LANGUAGE=JScript>
var address = new Array()
var i = 0
var wsh = new ActiveXObject("WScript.She
var fso = new ActiveXObject("Scripting.F
wsh.Run("cmd /C ipconfig /all > c:\\temp.txt", 0)
function getMacAddress() {
var file = fso.OpenTextFile("c:\\temp
var currentLine
var colon
while(file.AtEndOfStream != true)
{
currentLine = file.ReadLine()
if(currentLine.indexOf("Ph
{
colon = currentLine.indexOf(":")
address[i] = currentLine.substr(colon + 1)
i++
}
}
file.Close()
f = fso.GetFile("c:\\temp.txt"
f.Delete();
}
function writeAddress() {
for(j = 0; j < i; j++)
{
mac.innerHTML = mac.innerHTML + " <BR>Mac Address: " + address[j]
}
}
</SCRIPT>
<TITLE></TITLE>
</HEAD>
<BODY>
<P id=mac>
</P>
<Input type="Button" Value="Retrieve Mac Addresses" onClick="getMacAddress()">
<Input type="Button" Value="Display Addresses" onClick="writeAddress()">
</BODY>
</HTML>
Also, I had to put the code that runs ipconfig "wsh.run" at the start because when I had that line then tried to read it straight away I was getting a problem in that it was trying to read the file before it was created so it gave errors.
Also you will need to detect the o/s and if it is 95/98 and change the line. Wsh.Run("cmd" to wsh.Run("Command" and change the switch.
It is a start that needs some work, but there isn't any point if you need it to work on nn.
Ed