1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved Batch file to Ping

Discussion in 'Software Development' started by jaiswalrohitkr, May 19, 2017.

Thread Status:
Not open for further replies.
Advertisement
  1. jaiswalrohitkr

    jaiswalrohitkr Thread Starter

    Joined:
    Aug 6, 2012
    Messages:
    32
    I want to check few machines whether they are pingable or not by running a batch file. Please help me to check whether machines are reachable. Please share the batch file and I can edit it to check all the machines whether they are reachable.
     
  2. Sponsor

  3. Triple6

    Triple6 Rob Moderator

    Joined:
    Dec 26, 2002
    Messages:
    51,671
    This is pretty simple.

    Just save a file as a .bat with ping and the IP addresses, one per line.

    ie:

    ping 192.168.0.1
    ping 192.168.0.2
     
  4. jaiswalrohitkr

    jaiswalrohitkr Thread Starter

    Joined:
    Aug 6, 2012
    Messages:
    32
    I want the output as well. If say I want to ping some hostname like below.

    yahoo.com
    google.com
    gmail.com

    and I want to know if these sites are reachable or not.

    I want to run a batch file and have the output of it as well.

    thanks.
     
  5. Triple6

    Triple6 Rob Moderator

    Joined:
    Dec 26, 2002
    Messages:
    51,671
    Put a Pause at the end to wait for a key press or do you want to output to a file?

    Also, yahoo.com, google,com, and gmail.com are websites not "machines".
     
  6. jaiswalrohitkr

    jaiswalrohitkr Thread Starter

    Joined:
    Aug 6, 2012
    Messages:
    32
    I would like to have an output on a file whether the machines are reachable. Yahoo, google was just an example.
     
  7. Triple6

    Triple6 Rob Moderator

    Joined:
    Dec 26, 2002
    Messages:
    51,671
  8. jaiswalrohitkr

    jaiswalrohitkr Thread Starter

    Joined:
    Aug 6, 2012
    Messages:
    32
    did not understand
     
  9. Triple6

    Triple6 Rob Moderator

    Joined:
    Dec 26, 2002
    Messages:
    51,671
    That's the command. The >> pipes/appends the results to a file. A single > overwrites the file with the results.
     
  10. jaiswalrohitkr

    jaiswalrohitkr Thread Starter

    Joined:
    Aug 6, 2012
    Messages:
    32
    so if I have machine rohit-E7321, Jaiswal-A4321, how would be the batch file like and how do we get the output of it. If you can let me know separately.
     
  11. Triple6

    Triple6 Rob Moderator

    Joined:
    Dec 26, 2002
    Messages:
    51,671
    I don't understand what you are asking. What's the purpose of this file?

    To save it as a batch file use Notepad to save the above command to a file and give it an extension of .bat Double click to run it.
     
  12. draceplace

    draceplace

    Joined:
    Jun 8, 2001
    Messages:
    2,475
    This is a vbscript I used 10 years ago to monitor some network servers. It reads a .csv file for computer name (first column 'A') and pings if a Y in column F. I don't have that job anymore and don't have the necessary permissions to test this.

    I think there was another script that made the computer listing from Active Directory and I then added the Y if I wanted to monitor the machine.

    Code:
    '***********************************
    'Dan - draceplace
    '7/27/2005
    'deletes the previous log file
    'Reads pc names from comma delemented text file.
    'Pings the pc
    'Writes to log if no reply
    'emails log/report - outlook has changed and this may not work
    'Last Modified 8/18/2005
    '***********************************
    '*******File handling Constants*****
    Const ForReading = 1
    Const ForWriting = 2
    Const ForAppending = 8
    '******Counters********************
     badping_cnt = 0
     goodping_cnt = 0
     NotMonitored_cnt = 0
     TotPing_cnt = 0
     
    '******Date Time ******
    Dim CurrentDate, CurrentTime
    CurrentDate = Date
    CurrentTime = Time
    DateTime = CurrentDate & "," & CurrentTime
    
    '*******Input file Layout*********************
    Dim csvPCRecord '**for using the "split" on commas
    Dim strComputer, strPCdate, strPCtime, strPCou, strPCstat, strMonStat
    '*******File Definitions**********************
    LogFile = "C:\A1\PCLog.txt"
    InputFile = "C:\A1\List_pc2.csv"
    
    '**********************************************
    '**Start of Program****************************
    '********************Call Delete File Function (PCLog.txt)******
    '********************Don't call if LogFile doesn't exist!*******
    FnDeleteFile(LogFile)
    
    '****************************************************************
    '********open input and output files*****************************
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile(InputFile, ForReading)
     
    Set f = objFSO.Opentextfile(LogFile, ForWriting, True)
       f.WriteLine "Ping Report" & " " & DateTime 
    
    '****************************************************************
    '********Loop til end of input file******************************
    Do While objTextFile.AtEndOfStream <> True
      strLine = objtextFile.ReadLine
      If inStr(strLine, ",") Then     
         csvPCRecord = split(strLine, ",")
    '    Wscript.Echo vbCrLf & "PC Name: " & arrPCRecord(0)
    '    Wscript.Echo "PC User: " & arrPCRecord(1)
    'set up for calling ping routine
            strComputer = csvPCRecord(0)
            strMonStat = csvPCRecord(5)
    'see if PC is in Monitor Status       
         If inStr(strMonStat, "Y") <> 0 Then   
    '**************call the ping routine******************* 
            PING_Sub 
            TotPing_cnt = TotPing_cnt + 1
         Else
         NotMonitored_cnt = NotMonitored_cnt + 1   
         End If
      End If
    Loop
    '****End of Job Routine ***********************************************
    'Wscript.Echo vbCrLf & "Number of PC Pings: " & TotPing_cnt
    'Wscript.Echo vbCrLf & "Number of Successfull PC Pings: " & goodping_cnt
    'Wscript.Echo vbCrLf & "Number of BAD PC Pings: " & badping_cnt
    'Wscript.Echo vbCrLf & "Computers not Monitored: " & NotMonitored_cnt
    
    f.Writeline "Number of PC Pings: " & TotPing_cnt
    f.Writeline "Number of Successfull PC Pings: " & goodping_cnt
    f.Writeline "Number of BAD PC Pings: " & badping_cnt
    f.Writeline "Computers not Monitored: " & NotMonitored_cnt
    
    '***********Close Files.
    f.Close
    objTextFile.Close
    
    '*****Call the email routine*****
    Mailme_Sub
    
    '************************************************************************
    '****PING_Sub Sub Routine works on XP and Server 2003****
    '************************************************************************
    Sub PING_Sub
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colItems = objWMIService.ExecQuery _
        ("Select * from Win32_PingStatus " & _
            "Where Address = '" & strComputer & "'")
    For Each objItem in colItems
        If objItem.StatusCode = 0 Then
    '        WScript.Echo "Reply received."
            goodping_cnt = goodping_cnt + 1
        Else
    '        Wscript.Echo vbCrLf & "PC Name: " & strComputer
    '        Wscript.Echo " No reply received."
            badping_cnt = badping_cnt + 1
           f.WriteLine strComputer & " " & "No reply received"
          
        End If
    Next
    End Sub
    '*************************************************************************
    '****Mailme Sub Routine is for machines that don't have smpt installed****
    '*************************************************************************
    Sub Mailme_SUB
    Set objEmail = CreateObject("CDO.Message")
    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    '****Open the file for reading
    Set f = fso.OpenTextFile(LogFile, ForReading)
    'The ReadAll method reads the entire file into the variable BodyText
    BodyText = f.ReadAll
    '****Close the file
    f.Close
    Set f = Nothing
    Set fso = Nothing
    
    objEmail.From = "[email protected]"
    objEmail.To = "[email protected];[email protected]"
    objEmail.Subject = "Ping Report " & DateTime
    
    objEmail.Textbody = BodyText
    objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
            "mail1a"
    objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send
    Wscript.Echo "email notification sent"
    
    End Sub
    '*************************************************************************
    '**************************Delete Files *******************
    Function FnDeleteFile(StrFile)
        Dim FSO
        Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
        FSO.DeleteFile(StrFile)
    End Function
    '********************************************************************
    
    
    
     
  13. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1190209