twig123 Posted November 8, 2007 Share Posted November 8, 2007 (edited) Hey guys,I an in charge of managing several different system, that the user's are not always at. I have a project where I need to re-mediate issues with the systems by transferring a non-corrupted version of a file to the system that are online.So, I an in need of a tool to be able to ping a list of Computer/Host names and export the pingable and unpingable lists, where I can then C$ into the system and replace the needed file.Any ideas? does anything like this exist, or could someone help me automate this process?Thanks in advance Edited November 9, 2007 by twig123 Link to comment Share on other sites More sharing options...
twig123 Posted November 9, 2007 Author Share Posted November 9, 2007 (edited) Ok... I was able to get the pinging part down with the .bat file below:@echo off> pingLOG.txtEcho Running Pingsfor /f "tokens=*" %%I in (IPlist.txt) do call :pinger %%Igoto :eof:pingerecho %TIME% >> pingLOG.txtping -n 2 %1 >> pingLOG.txtCan someone help me, I need to change this so that it filters the Computers/Hosts into either Online or Offline (separate files would be fine, or a way to sort them in 1 file would be great).Thanks Edited November 9, 2007 by twig123 Link to comment Share on other sites More sharing options...
puntoMX Posted November 9, 2007 Share Posted November 9, 2007 This would fit better in the Network Forum part, moving it there . Link to comment Share on other sites More sharing options...
twig123 Posted November 9, 2007 Author Share Posted November 9, 2007 Thanks for moving my thread, I didnt know where it would go best.***I have 3 variables that can come of the ping tests:"Ping request could not find host""Request timed out""Reply"is there a way with 1 ping, that I can determine what the status is and write the 2 possible failures into 1 file, and any reply's into a dif. file? Link to comment Share on other sites More sharing options...
twig123 Posted November 12, 2007 Author Share Posted November 12, 2007 (edited) Ping! ... Pong?Anyone out there in scripting land?I have an idea of putting the ping output into a variable, and then righting some IF statements... but I dont know how to gather the ping results once the ping command has been give to be able to make it into a variable.I would really appreciate any help that you could give me.Thanks in advance Edited November 12, 2007 by twig123 Link to comment Share on other sites More sharing options...
kasandoro Posted November 12, 2007 Share Posted November 12, 2007 Try this out, I wrote it for checking long lists of hosts (just put one host per line in a text file):Const ForReading = 1Set objFSO = CreateObject("Scripting.FileSystemObject")Set objShell = CreateObject("WScript.Shell")If not objFSO.FileExists("servers.txt") THENwscript.echo "Please create a file named 'servers.txt' with one PC name to be pinged per line,"&_vbcrlf&"with a hard return at the end of each line."wscript.quitend iftempobj="temp.txt"Set objTextFile = objFSO.OpenTextFile("servers.txt", ForReading)logfile="results.csv"Set ofile=objFSO.CreateTextFile(logfile,True)strText = objTextFile.ReadAllobjTextFile.Closewscript.echo "Ping batch starting, please be patient. This could take some time to"&_vbcrlf&"finish, depending on the number of hosts to check. You "_&"will be "&vbcrlf&"notified upon the completion of this script."ofile.WriteLine ","&"Ping Report -- Date: " & Now() & vbCrLfarrComputers = Split(strText, vbCrLF)for each item in arrcomputersobjShell.Run "cmd /c ping -n 1 -w 1000 " & item & " >temp.txt", 0, TrueSet tempfile = objFSO.OpenTextFile(tempobj,ForReading)Do Until tempfile.AtEndOfStream temp=tempfile.readall striploc = InStr(temp,"[") If striploc=0 Then strip="" Else strip=Mid(temp,striploc,16) strip=Replace(strip,"[","") strip=Replace(strip,"]","") strip=Replace(strip,"w"," ") strip=Replace(strip," ","") End If If InStr(temp, "Reply from") Then ofile.writeline item & ","&strip&","&"Online." ElseIf InStr(temp, "Request timed out.") Then ofile.writeline item &","&strip&","&"No response (Offline)." ELSEIf InStr(temp, "try again") Then ofile.writeline item & ","&strip&","&"Unknown host (no DNS entry)."End If LoopNexttempfile.closeobjfso.deletefile(tempobj)ofile.writeline ofile.writeline ","&"Ping batch complete "&now()wscript.echo "Ping batch completed. The results will now be displayed."objShell.Run("""C:\Program Files\Microsoft Office\OFFICE11\excel.exe """&logfile)This might not be at all what you wanted to do...but I'll offer anyway Just put one server/hostname per line in a file named servers.txt in the same folder as this script and you'll be good to go. It creates a .csv file you can open in excel with the results. Link to comment Share on other sites More sharing options...
twig123 Posted November 12, 2007 Author Share Posted November 12, 2007 (edited) This is what I have so far:@echo off> OnlineLOG.txt@echo off> OfflineLOG.txtEcho ************************Echo ** Running Ping Tests **Echo ************************for /f "tokens=*" %%I in (IPlist.txt) do call :pinger %%Igoto :eof:pingerping -n 1 %1|find "Ping request could not find host"if not errorlevel 1 goto :failping -n 1 %1|find "Request timed out."if not errorlevel 1 goto :failEcho %1>> OnlineLOG.txt:failping -n 1 %1|find "Reply"Echo %1>> OfflineLOG.txt ..however it is buggy and slow becase it pings at least 2 times before confirming that the system is online. also the bug that I have is that ALL the hosts get written to the offlineLOG.txt instead of only the offline.Any tips on making this better?***@kasandoro - dude... that is sweet. I guess VBs is better than batch scripting anyways.. is there a way to auto sort the output within the script into online, no responce, or unknown host? that would be killer! ... and a status of current host would be cool as well if possible. Edited November 12, 2007 by twig123 Link to comment Share on other sites More sharing options...
geezery Posted November 13, 2007 Share Posted November 13, 2007 (edited) Here is a working sample for your needs. You can change the way computers are read in to array if you want, now they are hard coded to the script.'Define Objects'---------------------------------------------------------------------------------------Set objShell = CreateObject("WScript.Shell")Set objFSO = CreateObject("Scripting.FileSystemObject")'Set objNetwork = CreateObject("WScript.Network")Const ForAppending = 8'Create a txt file'---------------------------------------------------------------------------------------Set objFile = objFSO.OpenTextFile("C:\FalsePing.txt", ForAppending, True)'List of computersDim IP_ARRAY()'Change the size of the array also to here'---------------------------------------------------------------------------------------Redim IP_ARRAY(10)i=0'Array of target computers'---------------------------------------------------------------------------------------IP_ARRAY(0) = "10.13.56.14"IP_ARRAY(1) = "10.13.56.2"IP_ARRAY(2) = "10.13.56.3"IP_ARRAY(3) = "10.13.56.4"IP_ARRAY(4) = "10.13.56.5"IP_ARRAY(5) = "10.13.56.6"IP_ARRAY(6) = "10.13.56.7"IP_ARRAY(7) = "10.13.56.8"IP_ARRAY(8) = "10.13.56.9"IP_ARRAY(9) = "10.13.56.10"IP_ARRAY(10) = "10.13.59.11"For Each Host in IP_ARRAYIf Ping(IP_ARRAY(i)) = False Then 'Write the offline computername to FalsePing.txt'--------------------------------------------------------------------------------------- ObjFile.Writeline(IP_ARRAY(i) & " is not online") i=i+1Else'Copy the needed file'---------------------------------------------------------------------------------------'Uncomment this line if you want to copy a file. Now it only writes that the computer is online 'objFSO.CopyFile "C:\SourceFile.txt" , "C$\", OverwriteExisting ObjFile.Writeline(IP_ARRAY(i) & " is online")i=i+1End ifNextFunction objWMI(strComputer, strWQL) Dim wmiNS, objWMIService wmiNS = "\root\cimv2" Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS) 'connect to WMI Set objWMI = objWMIService.ExecQuery(strWQL) 'execute query Set objWMIService = NothingEnd FunctionFunction Ping(strRmtPC) Dim wmiQuery, objPing, objStatus, blnStatus wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strRmtPC & "'" Set objPing = objWMI(".", wmiQuery) For Each objStatus in objPing If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then blnStatus = False 'Not Reachable Else blnStatus = True 'Reachable End If Next Ping = blnStatus Set objPing = NothingEnd Function Edited November 13, 2007 by geezery Link to comment Share on other sites More sharing options...
Stoic Joker Posted November 13, 2007 Share Posted November 13, 2007 Angry IP scanner works well for that type of thing, and is small, fast, portable, & free. Link to comment Share on other sites More sharing options...
Brothersoft Posted November 15, 2007 Share Posted November 15, 2007 it's so easy,try it.P-Ping Tools http://www.brothersoft.com/internet/ping_t...ools_16678.htmlIP Ping tool http://www.brothersoft.com/internet/ping_t...tool_46097.htmlI believe two software could meet your need. Forrest Brothersoft Support Link to comment Share on other sites More sharing options...
Jacquidr Posted December 28, 2007 Share Posted December 28, 2007 HiI dunno if you have resolved this request but these are the changes I have made to your script.It will sort your list into 3 files - Online, Offline and UnknownHost.It works really well.The script:*****************************************************************::Ping Test Multiple Computersfor /f "tokens=*" %%I in (IPList.txt) do call :pinger %%Igoto :eof:pingerping -n 1 %1% |find "Reply from"if not errorlevel 1 echo %1>> Online.txtping -n 1 %1% |find "Request timed out"if not errorlevel 1 echo %1>> offline.txtping -n 1 %1% |find "could not find host"if not errorlevel 1 echo %1>> Unknownhost.txt::DONE*****************************************************************Regards Link to comment Share on other sites More sharing options...
ahkeer Posted January 7, 2008 Share Posted January 7, 2008 HiI dunno if you have resolved this request but these are the changes I have made to your script.It will sort your list into 3 files - Online, Offline and UnknownHost.It works really well.The script:*****************************************************************::Ping Test Multiple Computersfor /f "tokens=*" %%I in (IPList.txt) do call :pinger %%Igoto :eof:pingerping -n 1 %1% |find "Reply from"if not errorlevel 1 echo %1>> Online.txtping -n 1 %1% |find "Request timed out"if not errorlevel 1 echo %1>> offline.txtping -n 1 %1% |find "could not find host"if not errorlevel 1 echo %1>> Unknownhost.txt::DONE*****************************************************************RegardsThis worked great for me. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now