如何实现循环ping功能
<html>
<head></head>
<body>
<h2 align=center>Ping Test</h2>
<% Response.Buffer = true %>
<%
url = "server01"
Set objWShell = Server.CreateObject("WScript.Shell")
Set objCmd = objWShell.Exec("ping -n 1 " & url)
strPResult = objCmd.StdOut.Readall()
set objCmd = nothing: Set objWShell = nothing
strStatus = "离线"
if InStr(strPResult,"TTL=")>0 then strStatus = "在线"
response.write url & " 状态为: " & strStatus
response.write ".<br>" & replace(strPResult,vbCrLf,"<br>")
%>
</body>
</html>
url = "server01",是计算机名,以上代码单独运行没有问题。显示结果:
Ping Test
server02 状态为: 在线.
Pinging server02.swust.com [219.133.36.200] with 32 bytes of data:
Reply from 219.133.36.200: bytes=32 time=47ms TTL=115
Ping statistics for 219.133.36.200:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 47ms, Maximum = 47ms, Average = 47ms
我想把这个功能加到一个循环中,实现多台计算机的ping操作。下面是我的代码:
<%if request("action")="refreshpc" then
sql="select * from PcInfor "
set rs1=server.CreateObject("Adodb.recordset")
rs1.open sql,conn,1,1
Response.Buffer = true
for i=1 to rs1.recordcount
url = "<%=rs1(1)%>"
Set objWShell = Server.CreateObject("WScript.Shell")
Set objCmd = objWShell.Exec("ping -n 1 " & url)
strPResult = objCmd.StdOut.Readall()
set objCmd = nothing: Set objWShell = nothing
if InStr(strPResult,"TTL=")>0 then
conn.execute "update PcInfor set M_status="运行中" where ID="<%=rs1(0)%>"
else conn.execute "update PcInfor set M_status="未使用" where ID="<%=rs1(0)%>"
rs1.movenext
next
end if%>
无法运行,语法有问题吧。另外我还想实现获取计算机的登陆用户名。相关事宜联系QQ:50944078,随时在线。希望各位大侠帮帮忙。