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:/www/" & strIP & ".txt",0,true
sh.run "%comspec% /c ping -a " & strIP & " 〉 d:/www/" & strIP & "ping.txt",0,true
Set sh = nothing
'分析ping命令结果获取计算机名
Function GetComputerName(strIP)
set fso=CreateObject("scripting.filesystemobject")
set ts=fso.opentextfile("d:/www/" & 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:/www/" & 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
%>
这里很明显它获取到的是你的DNS服务器计算机名因为你的web服务器和你的客户机都不在同一个网段,
Request.UserHostName肯定是获取不到的。
这个是一个很常见的问题,Request.UserHostName有的时候获取到的还是IP而不是计算机名字。郁闷~~~我也期待高手来回答这个问题。
<script language=javascript>var WshShell =new ActiveXObject("WScript.Shell")
alert(WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%"))
//这一句是用来得到用户的计算机名称
alert(WshShell.ExpandEnvironmentStrings("%USERNAME%"))
//这一句是用来得到用户名
</script>
用JS实现吧,
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)