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

前端 未结 6 1530
被撕碎了的回忆
被撕碎了的回忆 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: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.

提交回复
热议问题