asp 讀取網卡mac地址

來源:互聯網
上載者:User
<%
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))

'由於讀取某IP的網卡MAC地址


'本程式調用arp命令通過查詢本機arp表讀取特定IP的MAC地址


'本程式需要“WSCRIPT.SHELL”和“Scripting.FileSystemObject”兩個組件,

'請確保您的伺服器可以正常使用這兩個組件

'本程式需要調用Cmd.exe程式,臨時檔案儲存結果,請確保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 > IpcAnd ipc > 0 Then
GetMac=Ucase(Trim(CStr(Mid(arr(3), phyc, typec - phyc))))
End If
End If
End function
%>



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.