0

我正在尝试编写一个脚本,它将提示您输入主机名,例如222012-DC01,它将通过or解析来自dns的IP 地址pingnslookup

然后它应该修改IP 地址以 ping 该站点的路由器。如果ip 地址10.123.2.1它应该 ping10.123.1.1该站点的路由器。

该脚本应该为您提供server offlinerouter offline的输出。

在一个管理数百个站点的环境中工作,我们拥有服务器的所有权,但不涉及路由器故障等网络事件。

非常感谢您的帮助...

4

1 回答 1

1

将来请发布您所拥有和尝试过的内容。这是一个经过测试的脚本

function get_ip(strTarget)
  set objShell = CreateObject("WScript.Shell")
  set objExec = objShell.Exec("ping -n 2 -w 1000 " & strTarget)
  strPingResults = LCase(objExec.StdOut.ReadAll)
  get_ip = ""
  if InStr(strPingResults, "reply from") then
    wscript.echo VbCrLf & strTarget & " responded to ping."
    set regEx = New RegExp
    regEx.Pattern = "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"
    set matches = regEx.Execute(strPingResults)
    if matches.count > 0 then
      get_ip = matches(0)
    end if
  else
    wscript.echo vbCrLf & strTarget & " did not respond to ping."
    wscript.quit 1
  end If
end function

function is_online(strTarget)
  set objShell = CreateObject("WScript.Shell")
  set objExec = objShell.Exec("ping -n 2 -w 1000 " & strTarget)
  strPingResults = LCase(objExec.StdOut.ReadAll)
  if inStr(strPingResults, "reply from") then
    is_online = true
  else
    is_online = false
  end If
end function

pcname = inputbox( "Give the pc-name to ping:")
ip = get_ip(pcname)
wscript.echo "ip of pc " & pcname & " is " & ip
aIp = split(ip, ".")
aIp(2) = 1
router = join(aIp, ".")
wscript.echo "pinging " & router
if is_online(strTarget) then
  wscript.echo "router is online"
else
  wscript.echo "router is offline"
end if
于 2012-07-27T14:02:16.660 回答