Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Ping Test Bat  (Read 13838 times)

0 Members and 1 Guest are viewing this topic.

Ryuk

    Topic Starter


    Adviser

    Thanked: 3
    • Experience: Beginner
    • OS: Unknown
    Ping Test Bat
    « on: January 08, 2012, 01:44:37 PM »
    Im tring to make a batch file that will run a ping test.  Basically, this is what I really have an Im going off memory

    @echo off

    1 Preform a self Ping Test?
    2 Enter a IP too Ping
    3 Exit

    if
    Ping 127.0.0.1
    else
    ping


    Exit

    Raven19528



      Hopeful
    • Thanked: 30
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Re: Ping Test Bat
      « Reply #1 on: January 08, 2012, 05:43:50 PM »
      What are you trying to accomplish here? You don't have this in any sort of Batch script language. Are you wanting a menu? What do you want the options to do?

      From what I can gather, try this:

      Code: [Select]
      @echo off
      :Menu
      cls
      echo 1 Perform a self Ping Test
      echo 2 Enter a IP to Ping
      echo 3 Exit
      echo.
      set /p ans=

      if "%ans%"=="1" (
        ping 127.0.0.1
        pause
        goto Menu
      )
      if "%ans%"=="2" (
        set /p ip=IP:
        ping %ip%
        pause
        goto Menu
      if "%ans%"=="3" (exit)
      goto Menu

      This program will require that you press 3 to exit. It also will only do something with a 1 2 or 3, and will display the Menu again if it receives anything else. When asking for something, please be much more specific as to what you want, as that is more helpful in the long run.
      "All things that are
      Are with more spirit chased than enjoy'd" -Shakespeare

      Ryuk

        Topic Starter


        Adviser

        Thanked: 3
        • Experience: Beginner
        • OS: Unknown
        Re: Ping Test Bat
        « Reply #2 on: January 11, 2012, 10:24:49 AM »
        I wanted to be able to run a batch file that opened a batch file for network testing.  I wanted to have three options as indicated there to be selected.  I havent done anything with dos for a while so sorry if the code seems noobish.  If its anything other then 3 I wanted it to come back as not a vaild choice.   

        Raven19528



          Hopeful
        • Thanked: 30
          • Computer: Specs
          • Experience: Experienced
          • OS: Windows 7
          Re: Ping Test Bat
          « Reply #3 on: January 11, 2012, 11:27:03 AM »
          I wanted to be able to run a batch file that opened a batch file for network testing.     

          Is there a reason to have the batch call another batch? It would seem simpler overall to keep it all within the same file. Currently it pings the loopback address with option 1, pings an entered IP for option 2, and exits for option 3. If you would like to add more functionality to it, it shouldn't be problematic to have it all happen within the construct it is in now.

          If its anything other then 3 I wanted it to come back as not a vaild choice.

          Easy enough. This goes in between the last two lines (notice they are the top and bottom lines in this snippet):

          Code: [Select]
          if "%ans%"=="3" (exit)
          echo Invalid Entry
          echo.
          echo Please try again
          pause
          goto Menu
          "All things that are
          Are with more spirit chased than enjoy'd" -Shakespeare

          Ryuk

            Topic Starter


            Adviser

            Thanked: 3
            • Experience: Beginner
            • OS: Unknown
            Re: Ping Test Bat
            « Reply #4 on: January 11, 2012, 11:34:01 AM »
            ummm.. No sorry, that was a grammer error on my part. 

            Ryuk

              Topic Starter


              Adviser

              Thanked: 3
              • Experience: Beginner
              • OS: Unknown
              Re: Ping Test Bat
              « Reply #5 on: January 21, 2012, 04:10:26 PM »
              What are you trying to accomplish here? You don't have this in any sort of Batch script language. Are you wanting a menu? What do you want the options to do?

              From what I can gather, try this:

              Code: [Select]
              @echo off
              :Menu
              cls
              echo 1 Perform a self Ping Test
              echo 2 Enter a IP to Ping
              echo 3 Exit
              echo.
              set /p ans=

              if "%ans%"=="1" (
                ping 127.0.0.1
                pause
                goto Menu
              )
              if "%ans%"=="2" (
                set /p ip=IP:
                ping %ip%
                pause
                goto Menu
              if "%ans%"=="3" (exit)
              goto Menu

              This program will require that you press 3 to exit. It also will only do something with a 1 2 or 3, and will display the Menu again if it receives anything else. When asking for something, please be much more specific as to what you want, as that is more helpful in the long run.

              sadly, it doesnt work.  I select each of the three options an it just exits

              Squashman



                Specialist
              • Thanked: 134
              • Experience: Experienced
              • OS: Other
              Re: Ping Test Bat
              « Reply #6 on: January 21, 2012, 08:42:10 PM »
              ummm.. No sorry, that was a grammer error on my part.


              sadly, it doesnt work.  I select each of the three options an it just exits
              Maybe a spelling grammar error. ;)

              Squashman



                Specialist
              • Thanked: 134
              • Experience: Experienced
              • OS: Other
              Re: Ping Test Bat
              « Reply #7 on: January 21, 2012, 08:48:05 PM »
              Missing a closing parenthesis.

              Ryuk

                Topic Starter


                Adviser

                Thanked: 3
                • Experience: Beginner
                • OS: Unknown
                Re: Ping Test Bat
                « Reply #8 on: January 22, 2012, 10:06:05 AM »
                I didnt build this, really I just wondered about how to get user input.  Also, what would of been wrong with my code

                Risen91



                  Rookie

                  • Experience: Beginner
                  • OS: Unknown
                  Re: Ping Test Bat
                  « Reply #9 on: January 22, 2012, 01:46:16 PM »
                  I didnt build this, really I just wondered about how to get user input.  Also, what would of been wrong with my code

                  The code you said at the top of the page wouldn't have worked because it isn't properly written, for example "1 Preform a self Ping Test?" would not have been displayed on screen and would have been interpreted as a command, rather than a comment. If you wanted the text to show you need to use the echo command (echo 1 Preform a self Ping Test?) as this tells Ms Dos that the following is not a command, but rather text to be printed on screen.
                  The user input as  said by Raven19528 is the "set /p ans=" part where it will set the variable "ans" to whatever the user inputs.

                  Hope this helped.

                  Ryuk

                    Topic Starter


                    Adviser

                    Thanked: 3
                    • Experience: Beginner
                    • OS: Unknown
                    Re: Ping Test Bat
                    « Reply #10 on: January 27, 2012, 12:12:03 AM »
                    I ment to say his code.  I can post mine but, I know it wont work an havent done anything with it since.

                    Raven19528



                      Hopeful
                    • Thanked: 30
                      • Computer: Specs
                      • Experience: Experienced
                      • OS: Windows 7
                      Re: Ping Test Bat
                      « Reply #11 on: January 30, 2012, 09:46:07 AM »
                      Missing a closing parenthesis.

                      Yes I am, try this on the last few lines:
                      Code: [Select]
                      if "%ans%"=="2" (
                        set /p ip=IP:
                        ping %ip%
                        pause
                        goto Menu
                      )
                      if "%ans%"=="3" (exit)
                      goto Menu
                      Notice I missed that final closing parenthesis. Try it now and see what happens.
                      "All things that are
                      Are with more spirit chased than enjoy'd" -Shakespeare

                      Ryuk

                        Topic Starter


                        Adviser

                        Thanked: 3
                        • Experience: Beginner
                        • OS: Unknown
                        Re: Ping Test Bat
                        « Reply #12 on: February 11, 2012, 10:05:59 AM »
                        I am able to select know.  The issue still remains where it wont allow to do a loop back or for entered ip's

                        Squashman



                          Specialist
                        • Thanked: 134
                        • Experience: Experienced
                        • OS: Other
                        Re: Ping Test Bat
                        « Reply #13 on: February 11, 2012, 05:17:34 PM »
                        You need to show us the exact code you are using.

                        Ryuk

                          Topic Starter


                          Adviser

                          Thanked: 3
                          • Experience: Beginner
                          • OS: Unknown
                          Re: Ping Test Bat
                          « Reply #14 on: February 11, 2012, 05:23:21 PM »
                          Im just useing what was posted by Raven

                          Squashman



                            Specialist
                          • Thanked: 134
                          • Experience: Experienced
                          • OS: Other
                          Re: Ping Test Bat
                          « Reply #15 on: February 11, 2012, 08:05:53 PM »
                          Doesn't mean you copied and pasted it correctly into your script. When you ask for help and someone says they need information from you, it would be prudent to give them the information they need. This isn't our first rodeo. Most of us have been doing this for a long time and beginners make rookie mistakes. If you want to be stubborn go right ahead but don't expect people to help you then.

                          Ryuk

                            Topic Starter


                            Adviser

                            Thanked: 3
                            • Experience: Beginner
                            • OS: Unknown
                            Re: Ping Test Bat
                            « Reply #16 on: February 12, 2012, 05:55:05 PM »
                            What  :-\  I coppied the exact portion of code that he chanced.  Also, I have had classes in programin an what not  ::)

                            Squashman



                              Specialist
                            • Thanked: 134
                            • Experience: Experienced
                            • OS: Other
                            Re: Ping Test Bat
                            « Reply #17 on: February 12, 2012, 07:44:06 PM »
                            Like I said.  If you are going to be stubborn about it nobody is going to help you.

                            Raven19528



                              Hopeful
                            • Thanked: 30
                              • Computer: Specs
                              • Experience: Experienced
                              • OS: Windows 7
                              Re: Ping Test Bat
                              « Reply #18 on: February 13, 2012, 05:18:42 PM »
                              Okay, Just so we are very clear, below is the code you are using right?

                              Code: [Select]
                              @echo off
                              :Menu
                              cls
                              echo 1 Perform a self Ping Test
                              echo 2 Enter a IP to Ping
                              echo 3 Exit
                              echo.
                              set /p ans=

                              if "%ans%"=="1" (
                                ping 127.0.0.1
                                pause
                                goto Menu
                              )
                              if "%ans%"=="2" (
                                set /p ip=IP:
                                ping %ip%
                                pause
                                goto Menu
                              )
                              if "%ans%"=="3" (exit)
                              goto Menu
                              "All things that are
                              Are with more spirit chased than enjoy'd" -Shakespeare

                              Ryuk

                                Topic Starter


                                Adviser

                                Thanked: 3
                                • Experience: Beginner
                                • OS: Unknown
                                Re: Ping Test Bat
                                « Reply #19 on: February 14, 2012, 01:45:48 PM »
                                Yes,  I took an coppied an pasted any new portions into it.   :-\

                                Squashman



                                  Specialist
                                • Thanked: 134
                                • Experience: Experienced
                                • OS: Other
                                Re: Ping Test Bat
                                « Reply #20 on: February 14, 2012, 01:54:47 PM »
                                I just tested the code and it works.  Maybe now you should do what I have been asking and copy the code from your batch file to here.

                                Ryuk

                                  Topic Starter


                                  Adviser

                                  Thanked: 3
                                  • Experience: Beginner
                                  • OS: Unknown
                                  Re: Ping Test Bat
                                  « Reply #21 on: February 14, 2012, 03:59:15 PM »
                                  did you try the self test?  Giveing it a IP  ::)

                                  Squashman



                                    Specialist
                                  • Thanked: 134
                                  • Experience: Experienced
                                  • OS: Other
                                  Re: Ping Test Bat
                                  « Reply #22 on: February 14, 2012, 06:56:35 PM »
                                  I give up. Raven he is all yours. Your code works just fine for me. If he isn't going to bother to post his code or show the output from the code he is using you might as well be a dentist trying to pull a tooth from a tiger that is still awake.

                                  Squashman



                                    Specialist
                                  • Thanked: 134
                                  • Experience: Experienced
                                  • OS: Other
                                  Re: Ping Test Bat
                                  « Reply #23 on: February 14, 2012, 08:40:23 PM »
                                  Finally figured out what he was talking about.  Thought I just mistyped something the first time I ran it.  Need to use delayed expansion on the IP variable.

                                  Ryuk

                                    Topic Starter


                                    Adviser

                                    Thanked: 3
                                    • Experience: Beginner
                                    • OS: Unknown
                                    Re: Ping Test Bat
                                    « Reply #24 on: February 17, 2012, 03:52:07 PM »
                                    so what is the issue with it :/

                                    Raven19528



                                      Hopeful
                                    • Thanked: 30
                                      • Computer: Specs
                                      • Experience: Experienced
                                      • OS: Windows 7
                                      Re: Ping Test Bat
                                      « Reply #25 on: February 17, 2012, 03:54:43 PM »
                                      Need to use delayed expansion on the IP variable.

                                      Never even thought about that. Makes sense now.

                                      Code: [Select]
                                      @echo off
                                      setlocal enabledelayedexpansion
                                      :Menu
                                      cls
                                      echo 1 Perform a self Ping Test
                                      echo 2 Enter a IP to Ping
                                      echo 3 Exit
                                      echo.
                                      set /p ans=

                                      if "%ans%"=="1" (
                                        ping 127.0.0.1
                                        pause
                                        goto Menu
                                      )
                                      if "%ans%"=="2" (
                                        set /p ip=IP:
                                        ping !ip!
                                        pause
                                        goto Menu
                                      )
                                      if "%ans%"=="3" (exit)
                                      goto
                                      "All things that are
                                      Are with more spirit chased than enjoy'd" -Shakespeare

                                      Ryuk

                                        Topic Starter


                                        Adviser

                                        Thanked: 3
                                        • Experience: Beginner
                                        • OS: Unknown
                                        Re: Ping Test Bat
                                        « Reply #26 on: February 17, 2012, 04:06:01 PM »
                                        Never even thought about that. Makes sense now.

                                        Code: [Select]
                                        @echo off
                                        setlocal enabledelayedexpansion
                                        :Menu
                                        cls
                                        echo 1 Perform a self Ping Test
                                        echo 2 Enter a IP to Ping
                                        echo 3 Exit
                                        echo.
                                        set /p ans=

                                        if "%ans%"=="1" (
                                          ping 127.0.0.1
                                          pause
                                          goto Menu
                                        )
                                        if "%ans%"=="2" (
                                          set /p ip=IP:
                                          ping !ip!
                                          pause
                                          goto Menu
                                        )
                                        if "%ans%"=="3" (exit)
                                        goto

                                        didnt work an menu isnt....

                                        Salmon Trout

                                        • Guest
                                        Re: Ping Test Bat
                                        « Reply #27 on: February 17, 2012, 04:29:20 PM »
                                        didnt work an menu isnt....

                                        Love these informative responses...


                                        Ryuk

                                          Topic Starter


                                          Adviser

                                          Thanked: 3
                                          • Experience: Beginner
                                          • OS: Unknown
                                          Re: Ping Test Bat
                                          « Reply #28 on: February 17, 2012, 04:39:37 PM »
                                          I thought some of the code got missing ::)

                                          Squashman



                                            Specialist
                                          • Thanked: 134
                                          • Experience: Experienced
                                          • OS: Other
                                          Re: Ping Test Bat
                                          « Reply #29 on: February 17, 2012, 08:18:02 PM »
                                          so what is the issue with it :/
                                          You know at some point you need to learn to fish just like you had to learn to talk and feed yourself to be self sufficient in this world. At least make an attempt at researching advice we give you.

                                          Lemonilla



                                            Apprentice

                                          • "Too sweet"
                                          • Thanked: 70
                                          • Computer: Specs
                                          • Experience: Experienced
                                          • OS: Windows 7
                                          Re: Ping Test Bat
                                          « Reply #30 on: February 29, 2012, 02:22:15 PM »
                                          Wrote this up and tested it, worked on win7.
                                          Sorry for it looking so ugly, but try it out.

                                          Code: [Select]
                                          @echo off
                                          title =Ping Tester
                                          :Menu
                                          color 07
                                          cls
                                          echo 1 Perform a self Ping Test
                                          echo 2 Enter a IP to Ping
                                          echo 3 Exit
                                          echo.
                                          set /p ans=
                                          cls

                                          if "%ans%"=="1" ping 127.0.0.1
                                          if "%ans%"=="1" pause
                                          if "%ans%"=="1" goto Menu


                                          if "%ans%"=="2" set /p ip=IP:
                                          if "%ans%"=="2" ping %ip%
                                          if "%ans%"=="2" pause
                                          if "%ans%"=="2" goto Menu

                                          if "%ans%"=="3" exit

                                          color 0c
                                          cls
                                          echo ERROR
                                          echo.
                                          echo please imput a number 1-3
                                          pause
                                          goto menu
                                          Quote from: patio
                                          God Bless the DOS Helpers...
                                          Quote
                                          If it compiles, send the files.