The_Immortal
25-10-2013, 11:59
Друзья, подкиньте, пожалуйста, скриптик, который записывает время в формате hh:mm:ss (с интервалом в 10 сек) и указывает фразу (желательно такую же, как и в утилите ping), когда заданный хост НЕдоступен.
Т.е. необходимо определять время, когда хост именно не отвечает. Успешный же ответ игнорировать и никуда не записывать.
Спасибо!
UPD: нашел вот такой скрипт
option explicit
' conHost -- адрес хоста для слежения
' conCheckInterval -- временной интервал
const conHost = "ya.ru", conCheckInterval = 10000
' создаём объект:
dim soWshShell : set soWshShell = CreateObject("WScript.Shell")
WScript.Quit Main()
function WriteLog(strText)
WScript.Stdout.WriteLine FormatDateTime(Time(), vbLongTime) & " " & strText
end function
function GetHostStatus(strHost)
dim oPing : set oPing = soWshShell.Exec("ping -n 1 " & strHost)
dim strOut : strOut = ""
do
WScript.Sleep 100
if not oPing.Stdout.AtEndOfStream then
strOut = strOut & oPing.Stdout.ReadAll
end if
loop until oPing.Status = 1
dim oRegExp : set oRegExp = new RegExp
oRegExp.IgnoreCase = true
oRegExp.Pattern = "[^ ]+:.+TTL=[^\r\n]+"
dim oMatches : set oMatches = oRegExp.Execute(strOut)
if oMatches.Count > 0 then
GetHostStatus = oMatches(0).Value
else
GetHostStatus = "ya.ru недоступен!"
end if
end function
function Main()
do
WriteLog(GetHostStatus(conHost))
WScript.Sleep(conCheckInterval)
loop
end functionПеределал его следующим образом:
option explicit
' conHost -- адрес хоста для слежения
' conCheckInterval -- временной интервал
const conHost = "ya.ru", conCheckInterval = 10000
' создаём объект:
dim FSO: set FSO=CreateObject("Scripting.FileSystemObject")
dim file: set file =FSO.CreateTextFile("bad_ping.txt")
dim soWshShell : set soWshShell = CreateObject("WScript.Shell")
WScript.Quit Main()
function WriteLog(strText)
WScript.Stdout.WriteLine FormatDateTime(Time(), vbLongTime) & " " & strText
end function
function GetHostStatus(strHost)
dim oPing : set oPing = soWshShell.Exec("ping -n 1 " & strHost)
dim strOut : strOut = ""
do
WScript.Sleep 100
if not oPing.Stdout.AtEndOfStream then
strOut = strOut & oPing.Stdout.ReadAll
end if
loop until oPing.Status = 1
dim oRegExp : set oRegExp = new RegExp
oRegExp.IgnoreCase = true
oRegExp.Pattern = "[^ ]+:.+TTL=[^\r\n]+"
dim oMatches : set oMatches = oRegExp.Execute(strOut)
if oMatches.Count > 0 then
GetHostStatus = oMatches(0).Value
else
file.WriteLine(FormatDateTime(Time(), vbLongTime) & " " & "ya.ru недоступен!")
GetHostStatus = "Inaccessible!.."
end if
end function
function Main()
do
WriteLog(GetHostStatus(conHost))
WScript.Sleep(conCheckInterval)
loop
end functionВ bad_ping.txt пишутся исключительно "плохие" пинги. Однако они задаются фразой "ya.ru недоступен!", а хотелось бы, чтобы туда попадало "Превышен интервал ожидания запроса" или "Заданный порт недоступен" и т.п. – именно те фразы, которые возвращает ping.
Такое возможно реализовать?
Т.е. необходимо определять время, когда хост именно не отвечает. Успешный же ответ игнорировать и никуда не записывать.
Спасибо!
UPD: нашел вот такой скрипт
option explicit
' conHost -- адрес хоста для слежения
' conCheckInterval -- временной интервал
const conHost = "ya.ru", conCheckInterval = 10000
' создаём объект:
dim soWshShell : set soWshShell = CreateObject("WScript.Shell")
WScript.Quit Main()
function WriteLog(strText)
WScript.Stdout.WriteLine FormatDateTime(Time(), vbLongTime) & " " & strText
end function
function GetHostStatus(strHost)
dim oPing : set oPing = soWshShell.Exec("ping -n 1 " & strHost)
dim strOut : strOut = ""
do
WScript.Sleep 100
if not oPing.Stdout.AtEndOfStream then
strOut = strOut & oPing.Stdout.ReadAll
end if
loop until oPing.Status = 1
dim oRegExp : set oRegExp = new RegExp
oRegExp.IgnoreCase = true
oRegExp.Pattern = "[^ ]+:.+TTL=[^\r\n]+"
dim oMatches : set oMatches = oRegExp.Execute(strOut)
if oMatches.Count > 0 then
GetHostStatus = oMatches(0).Value
else
GetHostStatus = "ya.ru недоступен!"
end if
end function
function Main()
do
WriteLog(GetHostStatus(conHost))
WScript.Sleep(conCheckInterval)
loop
end functionПеределал его следующим образом:
option explicit
' conHost -- адрес хоста для слежения
' conCheckInterval -- временной интервал
const conHost = "ya.ru", conCheckInterval = 10000
' создаём объект:
dim FSO: set FSO=CreateObject("Scripting.FileSystemObject")
dim file: set file =FSO.CreateTextFile("bad_ping.txt")
dim soWshShell : set soWshShell = CreateObject("WScript.Shell")
WScript.Quit Main()
function WriteLog(strText)
WScript.Stdout.WriteLine FormatDateTime(Time(), vbLongTime) & " " & strText
end function
function GetHostStatus(strHost)
dim oPing : set oPing = soWshShell.Exec("ping -n 1 " & strHost)
dim strOut : strOut = ""
do
WScript.Sleep 100
if not oPing.Stdout.AtEndOfStream then
strOut = strOut & oPing.Stdout.ReadAll
end if
loop until oPing.Status = 1
dim oRegExp : set oRegExp = new RegExp
oRegExp.IgnoreCase = true
oRegExp.Pattern = "[^ ]+:.+TTL=[^\r\n]+"
dim oMatches : set oMatches = oRegExp.Execute(strOut)
if oMatches.Count > 0 then
GetHostStatus = oMatches(0).Value
else
file.WriteLine(FormatDateTime(Time(), vbLongTime) & " " & "ya.ru недоступен!")
GetHostStatus = "Inaccessible!.."
end if
end function
function Main()
do
WriteLog(GetHostStatus(conHost))
WScript.Sleep(conCheckInterval)
loop
end functionВ bad_ping.txt пишутся исключительно "плохие" пинги. Однако они задаются фразой "ya.ru недоступен!", а хотелось бы, чтобы туда попадало "Превышен интервал ожидания запроса" или "Заданный порт недоступен" и т.п. – именно те фразы, которые возвращает ping.
Такое возможно реализовать?