〈%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%〉
〈%
strIP = Request.ServerVariables("REMOTE_ADDR")
strHost = Request.ServerVariables("REMOTE_HOST")
Set net = Server.CreateObject("wscript.network")
Set sh = Server.CreateObject("wscript.shell")
sh.run "%comspec% /c nbtstat -A " & strIP & " 〉 d:/wwwtemp/" & strIP & ".txt",0,true
sh.run "%comspec% /c ping -a " & strIP & " 〉 d:/wwwtemp/" & strIP & "ping.txt",0,true
Set sh = nothing
'分析ping命令结果获取计算机名
Function GetComputerName(strIP)
set fso=CreateObject("scripting.filesystemobject")
set ts=fso.opentextfile("d:/wwwtemp/" & strIP & "ping.txt")
computername=null
do while not ts.AtEndOfStream
data = ucase(trim(ts.readline))
if instr(data,"[") then
computername=trim(split(data,"[")(0))
computername=trim(replace(computername,"PINGING",""))
exit do
end if
loop
GetComputerName=computername
End Function
'分析nbtstat命令结果获取MAC地址
Function GetMACAddress(strIP)
Set fso = createobject("scripting.filesystemobject")
Set ts = fso.opentextfile("d:/wwwtemp/" & 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
GetMACAddress = macaddress
End Function
如何使用ASP获取远程的计算机名
本文介绍了一段使用VBScript从Web请求中获取客户端IP地址、主机名、MAC地址及计算机名称的示例代码。该脚本利用了nbtstat和ping命令来收集相关信息,并将结果保存到指定目录下的文本文件中。


被折叠的 条评论
为什么被折叠?



