[求助]获取mac地址问题
下面有两段获取mac地址的代码,我的系统(xp)运行后,只显示ip地址,就是不显示mac地址,是不是就是不支持xp啊?1、
<%
dim remoteaddr,mac
mac=getmac(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
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
%>
另一中方法:
<%
IP = Request.Servervariables("REMOTE_ADDR")
Mac = GetMACAddress(IP)
strHost = Request.Servervariables("REMOTE_HOST")
function GetMACAddress(IP)
Set net = Server.CreateObject("wscript.network")
Set sh = Server.CreateObject("wscript.shell")
sh.run "%comspec% /c nbtstat -A " & IP & " > c:\" & IP & ".txt",0,true
Set sh = nothing
Set fso = createobject("scripting.filesystemobject")
Set ts = fso.opentextfile("c:\" & IP & ".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:\" & IP & ".txt"
Set fso = nothing
GetMACAddress = macaddress
End function
%>
请高手们多执教啊!qq:63191203 在线等!
[此贴子已经被作者于2006-9-22 7:58:20编辑过]