<%
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 ))
'The MAC address of the NIC that reads an IP address
'The program calls the arp command to query the MAC address of a specific IP address from the local arp table.
'The program requires two components: "WSCRIPT. SHELL" and "Scripting. FileSystemObject,
'Make sure that your server can use these two components normally.
'This program uses the cmd.exe program to save the temporary files. Make sure that the IIS guest account has access to the program,
The 'temporary Directory has the 'authorization' 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: emp" 'temporary directory
SzTempFile = TempPath & oFileSys. GetTempName () 'get the temporary file name
Call oScript. Run ("cmd.exe/c ping-n 2" & IP, 0, True) 'arp table must have this IP address
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 (Mid (arr (3), phyc, typec-phyc ))))
End If
End If
End function
%>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service