Why MAC addresses suck
any idea how much of a pain it is to find info about obtaining hardware MAC addresses from clients using an ASP page? for windows machines:
strIP = Request.ServerVariables("HTTP_X_CISCO_BBSM_CLIENTIP")
strMac = GetMACAddress(strIP)
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
Set fso = nothing
GetMACAddress = macaddress
End Function
for *nix boxes:
strIP = Request.ServerVariables("HTTP_X_CISCO_BBSM_CLIENTIP")
strMac = GetMACAddress(strIP)
Function GetMACAddress(strIP)
Set net = Server.CreateObject("wscript.network")
set oShell = CreateObject("Wscript.Shell")
cmd = "%COMSPEC% /c ping -n 2 " & strIP & ">nul"
oShell.Run cmd,0,1
set oShell = nothing
Set sh = Server.CreateObject("wscript.shell")
sh.run "%comspec% /c arp -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,strIP) Then
macaddress = trim(split(split(data,strIP)(1),"DYNAMIC")(0))
Exit Do
End If
loop
ts.close
Set ts = nothing
Set fso = nothing
GetMACAddress = macaddress
End Function
substitute "REMOTE_ADDR" for "HTTP_X_CISCO_BBSM_CLIENTIP" if you're not using this weak-ass cisco proxy software like i am. i hate ASP.