<%
Dim remoteaddr
If Request.ServerVariables ("Http_x_forwarded_for") =empty Then
Remoteaddr=request.servervariables ("REMOTE_ADDR")
Else
Remoteaddr=request.servervariables ("Http_x_forwarded_for")
End If
If Getmac (remoteaddr) <> "" Then
Session ("Mac") = Getmac (remoteaddr)
End If
Sql= "SELECT * from MacAddress where mac_address= '" &getmac (remoteaddr) & ""
Set rst = Server. CreateObject ("ADODB.") Recordset ")
Rst.open sql,conn,1,3
Set rst=nothing
Response.Write (Getmac (REMOTEADDR))
' Due to read the NIC MAC address of an IP
' This procedure calls the ARP command to read a specific IP MAC address by querying the native ARP table
' This procedure needs ' WSCRIPT. SHELL "and" Scripting.FileSystemObject "two components,
' Make sure that your server can use both components properly
' This procedure needs to call the Cmd.exe program, the temporary file saves the result, please make sure that the IIS Guest account has access to the program,
' Temporary directory has the right to write ' limit.
function Getmac (IP)
On Error Resume Next
Dim Oscript
Dim Ofilesys, Ofile
Dim all, Sztempfile,ipc,phyc,typec
Dim TempPath
Set oscript = Server.CreateObject ("WSCRIPT. SHELL ")
Set Ofilesys = Server.CreateObject ("Scripting.FileSystemObject")
Temppath= "d:\temp\" temporary Directory
Sztempfile = TempPath & Ofilesys.gettempname () ' Get temporary file name
Call Oscript.run ("cmd.exe/c ping-n 2" & IP, 0, True) ' ARP table must have this IP
Call Oscript.run ("cmd.exe/c arp-a" & IP & ">" & Sztempfile, 0, True)
Set ofile = Ofilesys.opentextfile (sztempfile, 1, False, 0)
All=ofile.readall ()
Ofile.close
If (IsObject (ofile)) Then
Call Ofilesys.deletefile (Sztempfile, True)
End If
arr = Split (all, vbCrLf)
If UBound (arr) = 4 Then
Ipc= InStr (1, arr (2), "Internet address")
PHYC = InStr (1, arr (2), "Physical Address")
Typec = InStr (1, arr (2), "Type")
If typec > Phyc and PHYC > Ipcand IPC > 0 Then
Getmac=ucase (Trim (CStr (arr (3), PHYC, TYPEC-PHYC)))
End If
End If
End Function
%>