Luis Diaz
asked on
Windows batch & CMD: telnet command and export result
Hello experts,
I need to run telnet through cmd to check the access of url related to 6000 till 6100 port.
I am looking for a .bat that:
1-Read the various IP reported in a txt file with port:
Example:
url 6000
url 6001
Export the result for each line export result (in the same file).
File should be located at %cd% folder.
If you have questions, please contact me.
Thank you.
I need to run telnet through cmd to check the access of url related to 6000 till 6100 port.
I am looking for a .bat that:
1-Read the various IP reported in a txt file with port:
Example:
url 6000
url 6001
Export the result for each line export result (in the same file).
File should be located at %cd% folder.
If you have questions, please contact me.
Thank you.
As Bill Prew pointed out, issuing the telnet command leaves the process running. I'm hoping that piping a quit command into telnet will allow it to connect but then immediately exit. Save the following as a bat/cmd script, invoke it with a filename parameter, and it will read each URL Port in the file, attempt the telnet, and place the results in another file (filename.out).
@echo off
cls
IF "%1"=="" (
echo Usage: %0 filename
echo where filename contains URL Port tuples
) else (
echo.>%1.out
FOR /F "tokens=1-2" %%a IN (%1) DO (
echo quit | telnet %%a %%b
IF ERRORLEVEL 0 (
echo SUCCESS %%a %%b >>%1.out
) else (
echo FAIL %%a %%b >>%1.out
)
)
)
ASKER
Thank you for your comments.
If connection success report url +port : connection success else report connection fails.
Each line of log should be reported for every line reported in txt file. Pause of 3 second between each telnet.
Thank you again.
If connection success report url +port : connection success else report connection fails.
Each line of log should be reported for every line reported in txt file. Pause of 3 second between each telnet.
Thank you again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much for your advice and for your help.
I will be create a new question.
To contextualize the question: the goal is just to test that IT from my organization has properly opened port rules when we try to reach destination IP from organization network. so if telnet replies ok this will means that rules have been properly implemented.
Powershell is the unique approach for this?
I will be create a new question.
To contextualize the question: the goal is just to test that IT from my organization has properly opened port rules when we try to reach destination IP from organization network. so if telnet replies ok this will means that rules have been properly implemented.
Powershell is the unique approach for this?
When a telnet session succeeds, you will be left with it running. Do you also want the script to delete those after noting that the connection was successful? I think to do that would mean killing any active telnet tasks, will that work?
»bp