Overview

More Admin Tools

Articles

Downloads

 

TCP port check Windows 10 / Windows 11  |  02-Sep-2023    

Tutorial PortCheck 2.1         

PortCheck is a tiny command line tool for administrators and network admins. You can check if a remote device answers on a certain TCP port.

 

Content

What's new in version 2.1

Syntax

Examples

Individual text / text in other languages

Alarm in case of error

 

What's new in version 2.1 (Nov. 2020)

PortCheck has some new features:

  • Interactive mode with -i: You can create a shortcut on the desktop that asks for host and port when double-clicked. Very practical for ad hoc checks.

  • Individual text: With the parameters -replaceopentext and -replaceclosedtext the output can be completely customized. An interesting feature. For example, in the event of an error, instead of the "networker language" this text could appear: "No answer from Production-Machine1. Please call 5678". Furthermore, the output can be adapted to any language.

  • Alerting in case of error: PortCheck can now execute batch files in case of closed ports and in the "repaired case". Also only after several failures - completely configurable.

  • Bugfix: PortCheck 2.0 sometimes showed a wrong result when the own Windows firewall prohibited an outgoing port.

 

Syntax

PortCheck 2.1.0.8 by Lugrain Software 11/2020
Checks if a remote TCP port is opened or not.

Easy syntax:

PortCheck [-t] [-i] <hostname(s)> <port(s)>

Examples:

PortCheck -i               # interactive (ask for input)
PortCheck MyServer 80      # single check
PortCheck -t MyServer 443  # continuous

More complex syntax:

PortCheck [-t] [-i] [-w:<pause in s>] [-st] [-nc] [-oo] [-nl] [-tc]
          [-rcf:<batch file when closed>] [-rcc:<closed count>] [-rco] [-rch]
          [-rof:<batch file when open>] [-roc:<open count>] [-roo] [-roh]
          [-replaceopentext:<text when open>] [-replaceclosedtext:<text when closed>]
          <hostname(s)> <port(s)> [<timeout in ms>] [<name of logfile>] [<description>]


hostname(s)    One or more hostnames, separated by comma (no blanks)
port(s)        One or more TCP port numbers (separated by comma), a port
range          <startport>-<endport> or all wellknown ports 'knownports' or 'kp'
timeout        Can be 100-1000 (default: 1000ms)
filename       Logs everything to a specified file, including date and time
description    Your own description for the specified port

-t    Check the specified ports continuous
-w    Wait some time between checks (this is not the timeout)
-st   Show date and time in every line
-nc   No color: use default color instead of green and red
-oo   Only open: show only open ports
-nl   No lines: don't add separators
-tc   Toggle colors: swap green and red (port opened = alarm)
-bp   Beep: send acoustical signal in case of alarm (only with -t)

Examples:

PortCheck www.bing.com 80
PortCheck -t www.bing.com 80
PortCheck oracle-server1 1521 500 c:\temp\logfile.txt oracle
PortCheck -t -bp MyFileserver 139
PortCheck -t -w:10 MyFileserver 139,445
PortCheck -t -tc -bp sql-server1,sql-server2 1433 300
PortCheck -oo MyServer 1-1024
PortCheck MyServer knownports
PortCheck -t -rcf:"c:\data\closed.cmd" -rcc:3 -rco Citrix-Server 1494
PortCheck -t -replaceclosedtext:"Machine isn't working properly. Please call 1234!" Citrix-Server 1494

Returns ERRORLEVEL=0 when port is closed, ERRORLEVEL=1 when port is opened.

Examples


Simple check
PortCheck www.bing.com 80
Checks once whether www.bing.de answers on port 80 (HTTP).

Continuous
PortCheck -t www.bing.com 443
Checks continuously (as with the ping command) whether www.bing.com responds on port 443 (HTTPS).

Continuous check, ask for host and port
PortCheck -i
Queries host and port from user. You can create a shortcut on your desktop that calls PortCheck.exe -i. This allows you to run an ad hoc PortCheck at any time.

Show date and time
PortCheck -t -st Terminal-Server1 445
Checks continuously if Terminal-Server1 responds on port 445 (NetBIOS over TCP/IP). Displays date and time in every line.

Log to file with date and time
PortCheck -t -st Terminal-Server1 445 1000 c:\temp\Port445.txt
Checks continuously if Terminal-Server1 responds on port 445 (NetBIOS over TCP/IP). Displays date and time in every line and writes eyerything to a file.

Multiple hosts, single port
PortCheck -t Fileserver1,Fileserver2 3389
Checks continuously if Fileserver1 and Fileserver2 respond on port 3389 (RDP). Important: No blanks before and behind the comma.

Multiple hosts, multiple ports
PortCheck -t Fileserver1,Fileserver2 139,3389
Checks continuously if Fileserver1 and Fileserver2 respond on port 139 (NetBIOS) and port 3389 (RDP). Important: No blanks before and behind the comma.

Wait between two checks
PortCheck -t -w:10 Exchange-Server1 443
Checks continuously if Exchange-Server1 answers on Port 443. Waits 10 seconds between two checks.

Wait and Timeout
PortCheck -t -w:10 Cisco-Router1 22 600
Checks continuously if Cisco-Router1 answers on Port 22 (SSH). Waits 10 seconds between two checks. Timeout is set to 600ms.

Acoustic signal (Beep)
PortCheck -t -bp Citrix-Server1 1494
Checks continuously if Citrix-Server1 answers on port 1494 (ICA). A beep sounds if the server does not respond.

Acoustic signal (Beep) und reversed colors
PortCheck -t -bp -tc Citrix-Server1 1494
Checks continuously if Citrix-Server1 answers on port 1494 (ICA). A beep sounds if the server responds (answer = error).

Portscan on "Known Ports"
PortCheck Oracle-Server1 kp
Checks whether Oracle-Server1 responds on the "known ports". Checks about. 1100 known ports.

Portscan on port range
PortCheck Oracle-Server1 1-1024

Checks whether Oracle-Server1 answers on port 1-1024.

 

 

Individual text / text in other languages

With the parameters -replaceopentext and -replaceclosedtext the output can be customized. The specified text replaces the complete line which is normally output by PortCheck. So it is also possible to display the text in any language.


Example:

You want to monitor the functionality of a production machine with PortCheck. The machine with the IP address 10.5.1.1 responds on port 27000. The specialists - who do not have any special IT know-how - should be shown an understandable text in case of an error:

PortCheck -t -replaceopentext:"Production machine PM-1 is working properly" -replaceclosedtext:"No answer from Production Machine PM-1. Please restart or call 12345!" 10.5.1.1 27000

The following variables can be used within the text:

%host%      Hostname
%ip%        IP address
%port%      Port
%result%    Time in milliseconds or "timeout"
%datetime%  Date and time

 

 

Alarm in case of error

PortCheck is able to execute a batch file in case of an error. You can then use this batch file to perform further actions, such as sending a mail or SMS or initiating repair actions. Here are the possibilities:

  • Alarm can be triggered at the first error or after several successive errors. This avoids an immediate alarm at the first timeout.

  • One-time alarm possible. In this way, it can be configured so that only a single alarm is triggered in the event of a permanent failure.

  • Alarm in case of "repaired" possible. In this way all parties involved know that the problem has been fixed.

 

Example 1:
You want to use PortCheck to permanently monitor a web server on port 443. If the web server does not respond on this port 10 times in a row, the batch file Webserver-Error.cmd should be executed once. This is how it works:


PortCheck -t -rcf:"c:\data\Webserver-Error.cmd" -rcc:10 -rco WebServer1 443


With the parameter -rco the file is executed only once. It will only be executed again if there is at least one response on port 443. 


Example 2:

You want to use PortCheck to permanently monitor a file server on port 139. If the file server does not respond on this port 8 times in a row, the batch file Fileserver-Error.bat should be executed once. If the file server responds on the port 4 times in a row again, the batch file Fileserver-OK.bat should be executed. The command line is:


PortCheck -t -rcf:"c:\data\Fileserver-Error.bat" -rcc:8 -rco -rof:"c:\data\Fileserver-OK.bat" -roc:4 -roo FileServer1
139


Looks complicated, but it is not :). Everything that starts with "-rc" stands for "run when closed". Everything that starts with "-ro" stands for "run when open". For example, "-roo" stands for "run when open once".

The following parameters are automatically transferred to the batch files and can be used in them:

%1   Hostname
%2   IP address
%3   Port
%4   Time in milliseconds or "timeout"

 


>>> PortCheck Home

-----
Software: PortCheck
Category: TCP port check for Windows / Check TCP ports Windows 10
Type: Command line (cmd) 
Operating Systems: Windows 7 / Windows 8 / Windows 10 / Windows 11 / Windows Server 2008 / Windows Server 2012 / Windows Server 2016 / Windows Server 2019 / Windows Server 2022