0

I'm making some "Private" programs using Batch, and wan't a user to input an Internet Protocal into the batch input, and then when you hit enter, it takes that input, and runs a ping command on that IP? How would one go across such thing?

~ Husky

5
  • 2
    Edit your question and post what did you tried as code so far ! Commented Nov 23, 2016 at 12:12
  • set /p input=input something ?? Commented Nov 23, 2016 at 12:12
  • @Hackoo I didn't post what I tried as I've been scoping the internet for it but can't find SIMPLY explained things, I also am not "Secure" enough to post it as it has quite a bit of personal info (My IP ect) Commented Nov 23, 2016 at 12:19
  • set /p input=ping start cmd.exe /k ping goto Main pause Thats what I have so far, I need the "cmd.exe /k ping" to have the input after it. Commented Nov 23, 2016 at 12:22
  • 1
    @Husky Please take a look here to learn how to mark the answer as accepted Help Tour Commented Nov 23, 2016 at 12:59

2 Answers 2

1

As all others allready stated in the comments you are looking for

set /p myVariable= Asking for value here

You can then use this variable enclosing it within % ->

ping %myVariable%

should do the trick. You do not neccessarily need the start cmd.exe /k but you can use it.

Feel free to ask questions!

Sign up to request clarification or add additional context in comments.

Comments

0

You can give a try for this sample batch :

@echo off
Title Ping hosts tester 
:PingLoop
Color 0A & cls
echo Type the host IP to get info about its ping
set /p "IP=> "
ping %IP%
echo.
echo Hit any key to continue for another IP ...
pause>nul
Goto :PingLoop

EDIT : To check and validate the ip address entred by user before the pinging

@echo off
Title Check IP and Ping tester
:Main
cls & color 0E
echo Type your IP address :
Set /p "IP="
Call :CheckValidIP %IP%
cls
IF "%errorlevel%" EQU "0" ( 
    cls
    Color 0A
    echo %IP% is valid 
    Ping %IP%
    echo.
    echo Hit any key to continue for another IP ...
    pause>nul & Goto Main
) else (
    cls
    Color 0C
    echo %IP% is not valid
    echo Hit any key to continue for another IP ...
    pause>nul
)
Goto Main
::*********************************************************************************
:CheckValidIP <IP>
(
echo If IsValidIP("%~1"^) = True Then
echo    Wscript.Quit(0^)
echo Else
echo    Wscript.Quit(1^)
echo End If
echo Function IsValidIP(IPAddress^)
echo    Dim objRegExpr
echo    Set objRegExpr = New RegExp
echo    objRegExpr.Pattern = "\b((25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(25[0-5]|2[0-4]\d|1?\d?\d)\b"
echo    objRegExpr.Global = True
echo    objRegExpr.IgnoreCase = False
echo    IsValidIP = objRegExpr.Test(IPAddress^)
echo    Set objRegExpr = Nothing
echo End Function
)>"%tmp%\%~n0.vbs"
Cscript /nologo "%tmp%\%~n0.vbs"
Exit /b
::*********************************************************************************

2 Comments

Why this overkill?! This is to much in my oppinion and hard to understand if you just started with batch. gotos CScript and writing vbs from within the batch-script. Further you are not even attempting to explain what is going on...
Why not simply use findstr /r to check the IP instead of all this VBS stuff?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.