Hi,
You can try this code.....
Const ForReading = 1
Const ForWriting = 2
' check whether script is run in CSCRIPT (DOS-Environment)
' if not then execute using CSCRIPT.EXE and close WSCRIPT.EXE
host = WScript.FullName
hostexe = lcase(mid(host, InstrRev(host, "\")+1))
if not hostexe = "cscript.exe" then
' error! We run in WSCRIPT, so lets re-launch in CSCRIPT!
set wshshell = CreateObject("WScript.Shel
wshshell.run "CSCRIPT.EXE """ & WScript.ScriptFullName & """"
'quit
WScript.Quit
end If
'filenames for input/output
strComputerList = "ComputerList.txt"
strDefaultLogFile = "ping_results.csv"
' get access to input and output stream:
set input = WScript.StdIn
set output = WScript.StdOut
set wshobj = CreateObject("WScript.Shel
Set fso = CreateObject("Scripting.Fi
Set source = fso.OpenTextFile(strComput
Set target = fso.CreateTextFile(strDefa
' Read the list of computers to check
Do While source.AtEndOfStream <> True
strComputer = source.Readline
get_ping_state(strComputer
Loop
target.close
source.close
Function get_ping_state(strComputer
strCmd = "ping " & strComputer & " -n 1"
set objRun = wshobj.Exec(strCmd)
Do While objRun.Status = 0
wscript.sleep 50
loop
Do While Not objRun.StdOut.AtEndOfStrea
strText = objRun.StdOut.Readline
If InStr(strText, "Unknown host") > 0 Then
Wscript.Echo strComputer & ", Unknown host"
target.writeline strComputer & ",Unknown host"
End If
if instr(strText, "Request timed out") > 0 then
Wscript.Echo strComputer & ", Request timed out"
target.writeline strComputer & ",Request timed out"
end If
if instr(strText, "Reply from") > 0 then
Wscript.Echo strComputer & ", Reply"
target.writeline strComputer & ",Reply"
end If
if instr(strText, "Ping request could not find host") > 0 then
Wscript.Echo strComputer & ", Unknown host"
target.writeline strComputer & ",Unknown host"
end if
Loop
End Function
Main Topics
Browse All Topics





by: bsharathPosted on 2007-10-26 at 09:32:48ID: 20157012
Sorry cannot help with this code...
ation")
leSystemOb ject")
txt")
ipt.Shell" )
.Select
r.ColorInd ex = 19
lorIndex = 11
ld = True
n.AutoFit
But have a similar code that can do it...
Set objExcel = CreateObject("Excel.Applic
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
objExcel.Cells(1, 1).Value = "Machine Name"
objExcel.Cells(1, 2).Value = "On Line"
objExcel.Cells(1, 3).Value = "Off Line"
Set Fso = CreateObject("Scripting.Fi
Set InputFile = fso.OpenTextFile("servers.
Do While Not (InputFile.atEndOfStream)
HostName = InputFile.ReadLine
Set WshShell = WScript.CreateObject("WScr
Ping = WshShell.Run("ping -n 1 " & HostName, 0, True)
objExcel.Cells(intRow, 1).Value = HostName
Select Case Ping
Case 0 objExcel.Cells(intRow, 2).Value = "On Line"
Case 1 objExcel.Cells(intRow, 3).Value = "Off Line"
End Select
intRow = intRow + 1
Loop
objExcel.Range("A1:B1:C1")
objExcel.Selection.Interio
objExcel.Selection.Font.Co
objExcel.Selection.Font.Bo
objExcel.Cells.EntireColum
Save all the ip's or machine names in a "Servers.txt" file then run the script it will open a file with all ping results