使用ASP程序获取客户端MAC地址的方法

使用ASP程序获取客户端MAC地址,这是一个特殊的方法,用的地方比较少,经常在一些木马文件中看到这个。具体的方法: view sourceprint?01 <%    02 dim remoteaddr
    03 if Request.ServerVariables("HTTP_X_FORWARDED_FOR")=empty then
    04     remoteaddr=Request.ServerVariables("REMOTE_ADDR")
    05 else
    06     remoteaddr=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    07 end if
    08
    09 Response.Write("MAC地址是:"&GetMac(remoteaddr))
    10 '由于读取某IP的网卡MAC地址
    11 '本程序通过调用arp命令通过查询本机arp表读取特定IP的MAC地址
    12 '使用本程序需注意以下事项:
    13 '本程序需要“WSCRIPT.SHELL”和“Scripting.FileSystemObject”两个组件,请确保您的服务器可以正常使用这两个组件
    14 '本程序需要调用cmd.exe程序,请确保IIS来宾帐号对程序有访问权限。
    15 '本程序需要临时文件保存结果,请确保IIS来宾帐号对临时目录有写权限。
    16 '
    17 function GetMac(IP)
    18     On Error Resume Next
    19     Dim oScript
    20     Dim oFileSys, oFile
    21     Dim All, szTempFile,ipc,phyc,typec
    22     Dim TempPath
    23     Set oScript = Server.CreateObject("WSCRIPT.SHELL")
    24     Set oFileSys = Server.CreateObject("Scripting.FileSystemObject")
    25     TempPath="d:\temp\" '临时目录
    26     szTempFile = TempPath & oFileSys.GetTempName() ' 获取临时文件名
    27     Call oScript.Run ("cmd.exe /c ping -n 2 " & IP, 0, True) '保证arp表中有此IP
    28     Call oScript.Run ("cmd.exe /c arp -a " & IP & " > " & szTempFile, 0, True)
    29     Set oFile = oFileSys.OpenTextFile (szTempFile, 1, False, 0)
    30     All=oFile.ReadAll()
    31     oFile.Close
    32     If (IsObject(oFile)) Then
    33         Call oFileSys.DeleteFile(szTempFile, True)
    34     End If
    35     arr = Split(All, vbCrLf)
    36     If UBound(arr) = 4 Then
    37         ipc = InStr(1, arr(2), "Internet Address")
    38         phyc = InStr(1, arr(2), "Physical Address")
    39         typec = InStr(1, arr(2), "Type")
    40         If typec > phyc And phyc > ipc And ipc > 0 Then
    41             GetMac=Ucase(Trim(CStr(Mid(arr(3), phyc, typec - phyc))))
    42         End If
    43     End If
    44 End function
    45 %>