How to check outgoing connection with IP address, as well as with a specific port?

OK, we all know how to use PING to test the connection to the IP address. What I need to do is something similar, but check if my outgoing request to this IP address is successful, as well as the specific port (in this case 1775). The test should preferably be performed from the command line.

+8
ip
source share
6 answers

If there is a server on the target IP / port, you can use Telnet. Any response other than “unable to connect” indicates that you were able to connect.

+5
source share

Here is a small site that I made to check any outbound port. The server listens on all available TCP ports.

http://portquiz.net

telnet portquiz.net XXXX 
+52
source share

To automate the amazing portquiz.net service, I wrote a bash script:

 NB_CONNECTION=10 PORT_START=1 PORT_END=1000 for (( i=$PORT_START; i<=$PORT_END; i=i+NB_CONNECTION )) do iEnd=$((i + NB_CONNECTION)) for (( j=$i; j<$iEnd; j++ )) do #(curl --connect-timeout 1 "portquiz.net:$j" &> /dev/null && echo "> $j") & (nc -w 1 -z portquiz.net "$j" &> /dev/null && echo "> $j") & done wait done 
+8
source share

If you are testing TCP / IP, the cheapest way to test remote addr / port is to connect telnet to it and see if it connects. For protocols such as HTTP (port 80), you can even enter HTTP commands and receive HTTP responses.

eg,

 Command IP Port Telnet 192.168.1.1 80 
+5
source share

The fastest / most efficient way I've found is nmap and portquiz.net, described here: http://thomasmullaly.com/2013/04/13/outgoing-port-tester/ This scans the top 1000 most used ports:

 # nmap -Pn --top-ports 1000 portquiz.net Starting Nmap 6.40 ( http://nmap.org ) at 2017-08-02 22:28 CDT Nmap scan report for portquiz.net (178.33.250.62) Host is up (0.072s latency). rDNS record for 178.33.250.62: electron.positon.org Not shown: 996 closed ports PORT STATE SERVICE 53/tcp open domain 80/tcp open http 443/tcp open https 8080/tcp open http-proxy Nmap done: 1 IP address (1 host up) scanned in 4.78 seconds 

To scan them all (took 6 seconds instead of 5):

 # nmap -Pn -p1-65535 portquiz.net 
+1
source share

The @benjarobin bash script for testing the sequence of ports did not work for me, so I created this minimal example with a non-really single line (command line) that writes the output of the open ports from the sequence 1-65535 (all applicable communication ports) to the local file and suppress all other output:

 for p in $(seq 1 65535); do curl -s --connect-timeout 1 portquiz.net:$p >> ports.txt; done 

Unfortunately, it takes 18.2 hours to start, since the minimum connection timeout allowed an integer number of seconds with my old version of curl: 1. If you have a version of curl> = 7.32.0 (type "curl -V"), you can try decreasing decimal values, depending on how quickly you can connect to the service. Or try a smaller port range to minimize the duration.

In addition, it will be added to the ports.txt output file, so if you run it several times, you can delete the file first.

0
source share

All Articles