怎样通过Web方式获得对方的网卡MAC地址?

2025-05-23 07:51:58
推荐回答(1个)
回答1:

<%

strIP = Request.ServerVariables("REMOTE_ADDR")

strMac = GetMACAddress(strIP)

strHost = Request.ServerVariables("REMOTE_HOST")

Function GetMACAddress(strIP)

Set net = Server.CreateObject("wscript.network")

Set sh = Server.CreateObject("wscript.shell")

sh.run "%comspec% /c nbtstat -A " & strIP & " > c:" & strIP & ".txt",0,true

Set sh = nothing

Set fso = createobject("scripting.filesystemobject")

Set ts = fso.opentextfile("c:" & strIP & ".txt")

macaddress = null

Do While Not ts.AtEndOfStream

data = ucase(trim(ts.readline))

If instr(data,"MAC ADDRESS") Then

macaddress = trim(split(data,"=")(1))

Exit Do

End If

loop

ts.close

Set ts = nothing

fso.deletefile "c:" & strIP & ".txt"

Set fso = nothing

GetMACAddress = macaddress

End Function

%>





Say Hello To the MAC MAN





<%Response.Write("Your IP is : " & strIP & "
" & vbcrlf)%>

<%Response.Write("Your MAC is : " & strMac & vbcrlf)%>





后记:此程序中需要USER_****用户有C盘的写入权限,也可以将文中的“C:”改为有写权限的驱动器(或目录)也可。