2012-07-21 81 views
0

我试图写一个脚本,它会提示你主机一个“路由器”,说222012-DC01从此它将从通过DNS解决IP地址pingnslookup脚本来ping从ping一台单一的主机名

然后它应该修改IP地址以ping该站点的路由器。如果IP地址10.123.2.1它应该为该站点的路由器ping 10.123.1.1

该脚本应该给你一个输出服务器离线路由器离线

在一个环境中工作几百个站点,我们拥有服务器的所有权,而不是网络事件,如路由器故障。

你的帮助是非常赞赏...

+0

你有每个网站的netblocks的地图?他们是否都统一使用路由器地址的块中的第一个IP?如果没有,这是不可行的(如果是的话,一些示例网块定义将会有所帮助)。或者,10.x.x.x示例只是一个占位符,表示实际块中的公共地址是什么?或者,您的网络是否完全分割为10.x.x.x空间中的/ 16? – tripleee 2012-07-21 12:58:27

回答

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