China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 10:17
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Seeking help [Write a batch script to check if the telnet remote port is open] View 3,149 Replies 3
Original Poster Posted 2008-05-26 11:19 ·  中国 广东 广州 联通
新手上路
Credits 4
Posts 1
Joined 2008-05-26 10:42
18-year member
UID 119721
Gender Male
Status Offline
To check whether ports such as 22, 1521 on remote Linux platforms (multiple remote servers) are open by using telnet xxxx 22 /telnet xxx 1521 on this machine (Windows XP) and print the results to a file. How to write a batch script?
Floor 2 Posted 2008-05-26 19:58 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Floor 3 Posted 2017-04-10 13:28 ·  中国 上海 联通
初级用户
Credits 179
Posts 35
Joined 2003-06-03 00:00
23-year member
UID 3055
Gender Male
Status Offline
'nc' is not an internal or external command
Floor 4 Posted 2017-08-26 21:03 ·  中国 湖北 武汉 电信
新手上路
Credits 8
Posts 8
Joined 2017-08-21 22:22
8-year member
UID 182480
Gender Male
Status Offline
Let's try.

@echo off
set remoteip=1.1.1.1

:start
echo,
set port=
set /p port=Enter test port:
IF %PORT% LSS 0 goto erroe
if %PORT% GTR 65535 goto erroe
telnet %remoteip% %PORT% >nul 2>nul
if %errorlevel% ==0 (echo %remoteip%:%PORT% port service is normal.) else (echo %remoteip%:%PORT% port service is abnormal.)
echo %date% %time%>telnetlog.txt
echo %remoteip%:%PORT% port service is normal>>telnetlog.txt
echo, >>telnetlog.txt
pause
exit

:error
ECHO Port out of range
echo Re-enter a legal port
pause
goto start

[ Last edited by goltaxhs on 2017-8-26 at 21:16 ]
Forum Jump: