本程序屬於一種特別的方法。使用範圍比較有限,而且有一定的危險性。借鏡了asp後門裡的一些方法。下面是程式碼。
<%
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
Response.Write(GetMac(remoteaddr))
'由於讀取某IP的網路卡MAC位址
'本程式透過呼叫arp指令透過查詢本機arp表讀取特定IP的MAC位址
'使用本程式需注意以下事項:
' 本程式需要「WSCRIPT.SHELL」和「Scripting.FileSystemObject」兩個元件,請確保您的伺服器可以正常使用這兩個元件
' 本程式需要呼叫cmd.exe程序,請確保IIS來賓帳號對程式有存取權。
' 本程式需要暫存檔案儲存結果,請確保IIS來賓帳號對暫存目錄有寫入權限。
'
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" '臨時目錄
szTempFile = TempPath & oFileSys.GetTempName() ' 取得暫存檔案名稱
Call oScript.Run ("cmd.exe /c ping -n 2 " & IP, 0, True) '保證arp表中有此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 > ipc And ipc > 0 Then
GetMac=Ucase(Trim(CStr(Mid(arr(3), phyc, typec - phyc))))
End If
End If
End function
%>