How can I test an outbound connection to an IP address as well as a specific port?

前端 未结 6 1526
被撕碎了的回忆
被撕碎了的回忆 2020-12-24 03:15

OK, we all know how to use PING to test connectivity to an IP address. What I need to do is something similar but test if my outbound request to a given IP Address as well a

相关标签:
6条回答
  • 2020-12-24 04:12

    The fastest / most efficient way I found to to this is with nmap and portquiz.net described here: http://thomasmullaly.com/2013/04/13/outgoing-port-tester/ This scans to 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 sec instead of 5):

    # nmap -Pn -p1-65535 portquiz.net
    
    0 讨论(0)
  • 2020-12-24 04:17

    If there is a server running on the target IP/port, you could use Telnet. Any response other than "can't connect" would indicate that you were able to connect.

    0 讨论(0)
  • 2020-12-24 04:17

    Here is a small site I made allowing to test any outgoing port. The server listens on all TCP ports available.

    http://portquiz.net

    telnet portquiz.net XXXX
    
    0 讨论(0)
  • 2020-12-24 04:17

    To automate the awesome service portquiz.net, I did write 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
    
    0 讨论(0)
  • 2020-12-24 04:17

    If you're testing TCP/IP, a cheap way to test remote addr/port is to telnet to it and see if it connects. For protocols like HTTP (port 80), you can even type HTTP commands and get HTTP responses.

    eg

    Command IP          Port
    Telnet  192.168.1.1 80
    
    0 讨论(0)
  • 2020-12-24 04:21

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

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

    Unfortunately, this takes 18.2 hours to run, because the minimum amount of connection timeout allowed integer seconds by my older version of curl is 1. If you have a curl version >=7.32.0 (type "curl -V"), you might try smaller decimal values, depending on how fast you can connect to the service. Or try a smaller port range to minimise the duration.

    Furthermore, it will append to the output file ports.txt so if run multiple times, you might want to remove the file first.

    0 讨论(0)
提交回复
热议问题