程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> ASP技巧 >> ASP獲取客戶端MAC地址

ASP獲取客戶端MAC地址

編輯:ASP技巧

本程序屬於一種特別的方法。使用范圍比較有限,而且有一定的危險性。借鑒了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
%>

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved