ASP获取远程计算机名
一:您可以使用ASP的Request对象的方法ServerVariables方法得到客户机的机器名,如下:
远程客户机名
一般情况下,考虑到网络性能,Request.servervariables("REMOTE_HOST")返回客户的IP地址。您可以改变IIS的metabase的设定,允许IIS根据客户的IP地址查询用户的机器名。
您可以改变IIS的metabase的相关设定有两种方法:
1.在Asp中用代码设定
Dim oIIS
Dim vEnableRevDNS
Dim vDisableRevDNS
vEnableRevDNS = 1
vDisableRevDNS = 0
Set IIS = GetObject("IIS://localhost/w3svc")
oIIS.Put "EnableReverseDNS", vEnableRevDNS
oIIS.SetInfo
Set IIS = Nothing
%>
2. 运行命令行:cscript. C:\Inetpub\AdminScripts\adsutil.vbs set /w3svc/EnableReverseDNS "TRUE"
此时,Request.servervariables("REMOTE_HOST")返回客户的机器名。
所需的脚本文件adsutil.vbs及详细信息请参考以下链接:
HOWTO: Configure REMOTE_HOST to Perform. Reverse DNS
注:
此方法得到远程用户的IP
二:
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
%>
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12819884/viewspace-545113/,如需转载,请注明出处,否则将追究法律责任。