如何实现循环ping功能

jsj0111 2005-05-27 10:56:58
<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,随时在线。希望各位大侠帮帮忙。
...全文
473 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jsj0112 2005-05-28
  • 打赏
  • 举报
回复
你先用一个数组保存结果,然后再执行循环。
jsj0111 2005-05-27
  • 打赏
  • 举报
回复
诸位大侠,帮帮忙吧,如果有什么评价也说上两句吧,看在我一直在线的份上。
songsn 2005-05-27
  • 打赏
  • 举报
回复
上面的代码单独执行是可以的,但加入循环后就不行了!
jsj0111 2005-05-27
  • 打赏
  • 举报
回复
url = "127.0.0.1"
jsj0111 2005-05-27
  • 打赏
  • 举报
回复
不会吧,我用很多机子都试过了可以的。
iuhxq 2005-05-27
  • 打赏
  • 举报
回复
<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>
在我这里不能运行呀
jsj0111 2005-05-27
  • 打赏
  • 举报
回复
各位老鸟帮帮忙吧,是分不够么?

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧