Announcement

Collapse
No announcement yet.

Script or batch file to ping machine names

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script or batch file to ping machine names

    looking for a Script or batch file to ping by machine name or IP say 50 machine names in one shot...I am unfamilar with scripting. This is reagrding a XP\2003 operating system.

    anyone have any thoughts

  • #2
    Re: Script or batch file to ping machine names

    Create a batch file. Put in it:

    ping x.x.x.x
    ping x.x.x.x

    or

    ping computername
    ping computername

    Comment


    • #3
      Re: Script or batch file to ping machine names

      ping x.x.x.x
      ping x.x.x.x

      does not work ..tried it.....

      Comment


      • #4
        Re: Script or batch file to ping machine names

        You're right. I could swear that I've used that in the past.

        Comment


        • #5
          Re: Script or batch file to ping machine names

          errrr.... joeqwerty ment with x.x.x.x the IP address of the computer.
          Marcel
          Technical Consultant
          Netherlands
          http://www.phetios.com
          http://blog.nessus.nl

          MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
          "No matter how secure, there is always the human factor."

          "Enjoy life today, tomorrow may never come."
          "If you're going through hell, keep going. ~Winston Churchill"

          Comment


          • #6
            Re: Script or batch file to ping machine names

            It is easier to create a seperate file containing the names or ip-addresses of the computers,
            "File= Computers.txt"

            computer1
            computer2
            computer3
            x.x.x.x
            .
            .
            Here a batch that reads the computernames/addresses from the file, and ping them.
            Code:
            @echo off
            
            (Set InputFile=c:\Computers.txt)
            
            title,Pinging list of computers &color 9e
            
            ::datestamp
            for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
               for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
                  (set dow=%%m)&(set %%i=%%n)&(set %%j=%%o)&(set yy=%%p) ) )
            For /F "tokens=1,2 delims=:, " %%i in ('TIME /T') Do (Set HHMM=%%i%%j)
            
            (Set OutputFile=c:\Pinglog %yy%-%mm%-%dd% %HHMM%.txt)
            
            If Exist "%OutputFile%" Del "%OutputFile%"
            
            For /F "eol=;" %%* in ('type "%InputFile%"') do (
             >>"%OutputFile%" (echo.&echo.---------------&(
             echo.%%*;&(ping -a -n 2 -w 750 %%* | Find "."))
             )&echo.done %%*,)
            
            
            ::check
            start notepad.exe %OutputFile%
            The results are going to be written to a logfile with a date/time stamp in the file name.

            \Rems
            Last edited by Rems; 18th January 2008, 03:14. Reason: ^typo in variable

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: Script or batch file to ping machine names

              Tried the script which points to text file which rendered
              a blue screen pop up with :

              "The process cannot access the file because it is used by another process"
              for each computer name

              Comment


              • #8
                Re: Script or batch file to ping machine names

                tried it again and with each ping a notepad screen pops up which needs to be closed followed by another notepad screen

                Comment


                • #9
                  Re: Script or batch file to ping machine names

                  Script works...Thanks!!!Rems

                  Script works...Thanks!!!Rems



                  Enties for each machine name as follows:

                  machine name
                  c:\Pinglog 2008-01-18 1030.txt

                  machine name2
                  c:\Pinglog 2008-01-18 1030.txt

                  machine name3
                  c:\Pinglog 2008-01-18 1030.txt

                  etc........no mesage regarding success ..host record found..etc....

                  Also you have to keep on clikcing on notepad....bummer
                  Last edited by vitaminman; 21st January 2008, 14:42. Reason: Response

                  Comment


                  • #10
                    Re: Script or batch file to ping machine names

                    Originally posted by vitaminman View Post
                    Enties for each machine name as follows:

                    machine name
                    c:\Pinglog 2008-01-18 1030.txt

                    machine name2
                    c:\Pinglog 2008-01-18 1030.txt

                    machine name3
                    c:\Pinglog 2008-01-18 1030.txt

                    etc........no mesage regarding success ..host record found..etc....

                    Also you have to keep on clikcing on notepad....bummer
                    vitaminman, just edit your last post instead of replying to your self.

                    The batch is doing exact how it is programmed, it is working well here.
                    What is the windows version on the machine you are running the batch? I have tested the batch on Windows SRV 2003 and WinXP English and Dutch versions.

                    You did not mensioned what you want to do with the ping results, normaly just leave the dosbox open to see the results, in this case you won't be able to see all. That is why I use notepad. Notepad is started just once at the end of the batch, after the complete log is finished. If you do not want notepad to be executed, just skip the last two lines from the batch.

                    Because of the date/time stamp in name of the outputfile, it will write automatically a new file if you run the batch again after one minute (btw. c:\ root is not a recommened location for log files!). If you do not want the date/time to create new files, then just delete %yy%-%mm%-%dd% %HHMM% from the line (Set OutputFile=c:\Pinglog %yy%-%mm%-%dd% %HHMM%.txt).

                    What is exact in one logfile you get? You showed the name of the computer iand the name of the logfile are in the log??
                    - Make sure the last 'For /f' loop in the batch (4 lines, no empty lines between) is copied/paste exact how it is published, check if ('type "%InputFile%"') is on the starting line of this loop.
                    - The line (Set InputFile=c:\Computers.txt) must point to the file computers.txt in the exact location: <path>\filefullname
                    - Make sure the file computers.txt is in the right format.
                    - And last but not leased, do NOT give the batch the name ping.bat or ping.cmd, or any other name simular to a command used in the batch (like ping.exe). Oh -> That counts too for de names of all the files in the same folder of the batch.



                    Tried the script which points to text file which rendered
                    a blue screen pop up with :
                    "The process cannot access the file because it is used by another process"
                    for each computer name
                    The popup is giving the solution.
                    The blue screen (color 9e) is intended, you can change color in the batch.
                    What should appear on the blue field is, a kind of progress indicator, telling when each computer from the list is pinged.


                    \Rems
                    Last edited by Rems; 19th January 2008, 00:21.

                    This posting is provided "AS IS" with no warranties, and confers no rights.

                    __________________

                    ** Remember to give credit where credit's due **
                    and leave Reputation Points for meaningful posts

                    Comment


                    • #11
                      Re: Script or batch file to ping machine names

                      Originally posted by Rems View Post
                      It is easier to create a seperate file containing the names or ip-addresses of the computers,
                      "File= Computers.txt"

                      computer1
                      computer2
                      computer3
                      x.x.x.x
                      .
                      .
                      Here a batch that reads the computernames/addresses from the file, and ping them.
                      Code:
                      @echo off
                      
                      (Set InputFile=c:\Computers.txt)
                      
                      title,Pinging list of computers &color 9e
                      
                      ::datestamp
                      for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
                         for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
                            (set dow=%%m)&(set %%i=%%n)&(set %%j=%%o)&(set yy=%%p) ) )
                      For /F "tokens=1,2 delims=:, " %%i in ('TIME /T') Do (Set HHMM=%%i%%j)
                      
                      (Set OutputFile=c:\Pinglog %yy%-%mm%-%dd% %HHMM%.txt)
                      
                      If Exist "%OutputFile%" Del "%OutputFile%"
                      
                      For /F "eol=;" %%* in ('type "%InputFile%"') do (
                       >>"%OutputFile%" (echo.&echo.---------------&(
                       echo.%%*;&(ping -a -n 2 -w 750 %%* | Find "."))
                       )&echo.done %%*,)
                      
                      
                      ::check
                      start notepad.exe %OutputFile%
                      The results are going to be written to a logfile with a date/time stamp in the file name.

                      \Rems
                      Thank you Rems. It worked first time and I'm sure my boss will be impressed with "my" scripting knowledge!

                      Comment


                      • #12
                        Re: Script or batch file to ping machine names

                        You owe me one supapat!

                        Glad I could help.

                        ---
                        For the ping.exe I added the -a switch. So, in case you have ipaddresses in list of computers, the output now also shows the dns name of the computer.

                        But if you just want to know whether a computer is pingable or not, w/out further details (like in this batch; http://forums.petri.com/showthread.p...1303#post91303)

                        This is the part to replace with
                        Code:
                        :cut:
                        
                        For /F "usebackq eol=;" %%* In ("%InputFile%") Do (
                         Ping.exe -n 2 -w 750 %%* | Find/i "TTL=" >Nul && (
                         echo.%%* 	"was PINGABLE">>"%OutputFile%")|| (
                         echo.%%* 	"was NOT pingable">>"%OutputFile%")
                         echo.done %%*,)
                        
                        :cut:
                        Where && means: 'if succesfull then'.
                        And || means: 'if not succesfull then'.

                        \Rems
                        Last edited by Rems; 23rd January 2008, 21:23.

                        This posting is provided "AS IS" with no warranties, and confers no rights.

                        __________________

                        ** Remember to give credit where credit's due **
                        and leave Reputation Points for meaningful posts

                        Comment

                        Working...
                        X