如何测试到 IP 地址以及特定端口的出站连接?
好的,我们都知道如何使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是我制作的一个小站点,允许测试任何传出端口。服务器侦听所有可用的 TCP 端口。
http://portquiz.net
Here is a small site I made allowing to test any outgoing port. The server listens on all TCP ports available.
http://portquiz.net
如果目标 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.
为了自动化很棒的服务 portquiz.net,我编写了一个 bash 脚本:
To automate the awesome service portquiz.net, I did write a bash script :
我发现最快/最有效的方法是使用此处描述的 nmap 和 portquiz.net: http://thomasmullaly.com/2013/04/13/outgoing-port-tester/ 这会扫描前 1000 个最常用的端口:
要扫描全部端口(花费 6 秒而不是 5 秒):
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:
To scan them all (took 6 sec instead of 5):
如果您正在测试 TCP/IP,测试远程地址/端口的一种廉价方法是远程登录到它并查看它是否连接。对于 HTTP(端口 80)等协议,您甚至可以键入 HTTP 命令并获取 HTTP 响应。
例如
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
@benjarobin 用于测试一系列端口的 bash 脚本示例对我来说不起作用,因此我创建了这个最小的非真正一行(命令行)示例,该示例从一系列 1- 中写入打开端口的输出65535(所有适用的通信端口)到本地文件并抑制所有其他输出:
不幸的是,这需要 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:
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.