将来请发布您所拥有和尝试过的内容。这是一个经过测试的脚本
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