ASP獲取客戶端MAC地址 - 中國WEB開發者網絡 (http://www.webasp.net) -- 技術教程 (http://www.webasp.net/article/) --- ASP獲取客戶端MAC地址 (http://www.webasp.net/article/17/16594.htm) |
| -- 作者:未知 -- 發佈日期: 2005-02-23 |
| 本程序屬於一種特別的方法。使用範圍比較有限,而且有一定的危險性。借鑒了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 %> |
| webasp.net |