6

I need to check if client can connect to server on specific TCP port. Server is listening on it. Tried "telnet server_IP port" but telnet is stuck when I see that it's connected to the server. Seems telnet waits for specific reply from the server.

What I need is just to check if I can connect to the server from this workstation. Is there any way to do this? I would prefer Windows tools like telnet or something else.

EDIT: The main goal is to check that particular workstation can reach the server on this port. It's a part of a diagnostic tool. This tool is a simple script being run from the server to diagnos different aspects of this client/server system. It takes workstation name and checks if it's possible to connect to the server from this workstation. I'd like to check connectivity by a standard tool like telnet or anything else from Microsoft, preferably it should be already installed on workstation. I plan to run it by psexec from Sysinternals on workstation and receive the result on the server.

6
  • What service is running on that port, and what exactly are you trying to test? This makes a world of difference.
    – Dan
    Jan 24, 2012 at 11:11
  • @Dan: It's my custom-protocol TCP server. I'm trying to test if client connectivity to the server is not blocked by firewall Jan 24, 2012 at 11:13
  • Hang on, you mean you've written an application that listens on a port? So why not use the client to test, or get it to respond to Telnet. You're going to have to connect to that port to prove anything, and the only way to do that is to connect with something that understands what its connecting to
    – Dan
    Jan 24, 2012 at 11:15
  • @Dan: added some details to the question Jan 24, 2012 at 13:52
  • To clarify, you have a tool that is supposed to diagnose whether a client can connect to the server using a standard tool from the client like Telnet, but when you make the connection it's not made to give a response to indicate or log if the connection was successfully made? Jan 24, 2012 at 14:10

4 Answers 4

3

Try portqry , the Microsoft command line port scanner. This will tell you what ports you can connect to from a system

4
  • 1
    Must be something downloadable or installable??
    – Chris S
    Jan 24, 2012 at 14:21
  • Yes (can't put the link in till I get to a full web client)
    – Jim B
    Jan 24, 2012 at 14:23
  • This is awesome. If you are looking for something netcat-like but specifically just to answer the edge case question of "is this listening", this is very probably the swiss army knife you are looking for. Tool itself is undated, but winzip self-extractor is dated 1997. The readme file just points to this URL <-- stop and give that a quick look
    – i336_
    Dec 26, 2018 at 13:31
  • 1
    @i336_ oh it's ancient. Nowadays I'd probably just use powershell like: $Socket = New-Object Net.Sockets.TcpClient; $ErrorActionPreference = 'SilentlyContinue'; $Socket.Connect($Computer, $Port)
    – Jim B
    Dec 28, 2018 at 18:26
3

If telnet hostname port results in a blank screen with a cursor in the top-left corner, you are connected.

No further tools are necessary.

2
  • Added details to the question. I'm running it from the server by psexec, I cannot see its blank screen. Jan 24, 2012 at 13:59
  • 1
    Also, one may need to enable telnet first. May 11, 2016 at 15:00
2

Here is a VBScript TCP Ping solution I came up with using the MSXML2 ServerXMLHTTP control to test tcp connectivity to a port. It should work on most systems without any additional downloads.

address = "www.example.com"
WScript.Echo "http: " & TCPPing( address, 80)
WScript.Echo "ssh: " & TCPPing( address, 22)
WScript.Echo "smb: " & TCPPing( address, 139)
WScript.Echo "https: " & TCPPing( address, 443)

Function TCPPing( address, port )
  Set xhr = WScript.CreateObject("MSXML2.ServerXMLHTTP")
  xhr.SetTimeouts 8000,8000,8000,8000
  On Error Resume Next
  xhr.Open "GET", "http://" & address & ":" & port, False
  xhr.Send
  Select Case Err.Number
    ' ok, tcp connect but no web response, 401 auth failure
    Case 0,  -2147012744, -2147024891
      msg = "OK"
    Case -2147012867
      msg = "Connection Rejected"
    Case -2147012894
      msg = "Timed out"
    Case -2147012889
      msg = "Could not resolve address"
    Case -2147467259
      msg = "Cannot test that port with this tool"
    Case Else
      msg = "Unknown error " & Err.Number
  End Select
  On Error Goto 0
  Set xhr = Nothing
  TCPPing = msg
End Function
1
  • I like this one because it can be used without admin rights, even if telnet is turned off.
    – hibbelig
    Feb 3, 2016 at 14:09
1

If you're testing firewalls blocking the port, instead of your custom application run netcat on the server machine on that port in question, then connect to it from the client and netcat will let you see the results. That will tell you if the port is blocked or not and not throw in variables regarding your application's functionality.

3
  • Tnx for the answer. Added details to the question. Server is running so the port is occupied. It's fine just to connect and immediately disconnect. Also I cannot check connectivity by my client app, that's why I'm looking for something like telnet. Jan 24, 2012 at 13:58
  • You don't need anything but telnet on the client to connect to netcat on the server, but you would have to close down your application for a few moments to run with netcat. If your application isn't able to spit out a diagnostic code or reply to telnet, then you're going to get a blank screen with a cursor in the corner and not know if it's really talking to your application or if there's a connection issue. Jan 24, 2012 at 14:09
  • You could try glomming a fix together by having an executable statically compiled into a shared directory and running it from that UNC or shared drive on the client...netcat can make netcat connections to itself. Jan 24, 2012 at 14:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .