Linux‎ > ‎

Quick ways to test remote machine port availability

Thank you for visiting this page, this page has been update in another link Quick ways to test remote machine port availability

To be aware is that in nowadays, most of remote servers drop unexpected packets instead of giving a refuse response. Hence, the port is not available to you.

Also, in this article, I'm try to just use most common tools available on linux, I know there are a lot more tools available, for example nmap, netcat etc..

Telnet

  Very popular tool in old days, but now on most machine, it's gone.
  $ telnet yahoo.ca 80
Trying 98.139.102.145...
Connected to yahoo.ca.
Escape character is '^]'.

Curl


$ curl http://yahoo.ca:80
<!-- rc2.ops.sp1.yahoo.com uncompressed/chunked Sat Nov  9 05:16:33 UTC 2013 -->

wget

$ wget http://yahoo.ca:80
--2013-11-08 21:56:04--  http://yahoo.ca/
Resolving yahoo.ca... 68.180.206.184, 98.139.102.145
Connecting to yahoo.ca|68.180.206.184|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://ca.yahoo.com/ [following]
--2013-11-08 21:56:04--  http://ca.yahoo.com/
Resolving ca.yahoo.com... 206.190.36.45, 206.190.36.105, 2001:4998:c:401::c:9102, ...
Connecting to ca.yahoo.com|206.190.36.45|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “index.html”

    [ <=>                                                                                                                ] 195,921     --.-K/s   in 0.06s  

2013-11-08 21:56:05 (3.35 MB/s) - “index.html” saved [195921]

NC

$ nc yahoo.ca 80 </dev/null ; echo $?
<HEAD><TITLE>Invalid HTTP Request</TITLE></HEAD>
<BODY BGCOLOR="white" FGCOLOR="black">
<FONT FACE="Helvetica,Arial"><B>
 Bad request syntax</B></FONT>

<!-- default "Invalid HTTP Request" response (400) -->
</BODY>
0

$nc -z yahoo.ca 80
Connection to yahoo.ca 80 port [tcp/http] succeeded!

0 -- port available, 1 -- not available

BASH

$cat </dev/tcp/yahoo.ca/80
^C

Theory seems good, but doesn't work in this case.
/dev/tcp/host/port
    If host is a valid hostname or Internet address, and port is an integer port number
    or service name, bash attempts to open a TCP connection to the corresponding socket.
/dev/udp/host/port
    If host is a valid hostname or Internet address, and port is an integer port number
    or service name, bash attempts to open a UDP connection to the corresponding socket.





Comments