如何测试到 IP 地址以及特定端口的出站连接?

发布于 2024-11-08 11:54:08 字数 106 浏览 0 评论 0原文

好的,我们都知道如何使用 PING 来测试 IP 地址的连通性。我需要做的是类似的事情,但测试我对给定 IP 地址以及特定端口(在本例中为 1775)的出站请求是否成功。最好从命令提示符下执行测试。

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 as a specif port (in the present case 1775) is successful. The test should be performed preferably from the command prompt.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

岁月静好 2024-11-15 11:54:08

这是我制作的一个小站点,允许测试任何传出端口。服务器侦听所有可用的 TCP 端口。

http://portquiz.net

telnet portquiz.net XXXX

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
夜访吸血鬼 2024-11-15 11:54:08

如果目标 IP/端口上有服务器正在运行,则可以使用 Telnet。除“无法连接”之外的任何响应都表明您能够连接。

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.

享受孤独 2024-11-15 11:54:08

为了自动化很棒的服务 portquiz.net,我编写了一个 bash 脚本:

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

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
够钟 2024-11-15 11:54:08

我发现最快/最有效的方法是使用此处描述的 nmap 和 portquiz.net: http://thomasmullaly.com/2013/04/13/outgoing-port-tester/ 这会扫描前 1000 个最常用的端口:

# 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

要扫描全部端口(花费 6 秒而不是 5 秒):

# nmap -Pn -p1-65535 portquiz.net

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
初雪 2024-11-15 11:54:08

如果您正在测试 TCP/IP,测试远程地址/端口的一种廉价方法是远程登录到它并查看它是否连接。对于 HTTP(端口 80)等协议,您甚至可以键入 HTTP 命令并获取 HTTP 响应。

例如

Command IP          Port
Telnet  192.168.1.1 80

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
这样的小城市 2024-11-15 11:54:08

@benjarobin 用于测试一系列端口的 bash 脚本示例对我来说不起作用,因此我创建了这个最小的非真正一行(命令行)示例,该示例从一系列 1- 中写入打开端口的输出65535(所有适用的通信端口)到本地文件并抑制所有其他输出:

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

不幸的是,这需要 18.2 小时才能运行,因为我的旧版本的curl允许的最小连接超时量为整数秒为1。如果您如果curl 版本>=7.32.0(输入“curl -V”),您可以尝试更小的十进制值,具体取决于您连接到服务的速度。或者尝试较小的端口范围以最大程度地缩短持续时间。

此外,它将附加到输出文件 ports.txt,因此如果运行多次,您可能需要先删除该文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文