如何检查开放端口是TCP还是HTTP?

时间:2022-01-20 20:56:38

Specifically, I have a Windows server (Windows 7), but the netstat -an command only shows whether ports are TCP or UDP. I thought these were the only kinds of ports, but node.js seems to distinguish between HTTP ports and TCP ports (example at bottom of linked page). I'm currently using node.js in a program that will run on my server, and it opens HTTP ports by default. These appear as TCP ports under netstat -an.

具体来说,我有一个Windows服务器(Windows 7),但netstat -an命令仅显示端口是TCP还是UDP。我认为这些是唯一的端口类型,但node.js似乎区分HTTP端口和TCP端口(链接页面底部的示例)。我目前在我的服务器上运行的程序中使用node.js,默认情况下会打开HTTP端口。它们在netstat -an下显示为TCP端口。

Is there a command line trick for distinguishing whether an open port on this server is HTTP or TCP? I make requests to my Information Technology office about ports that I need on this server, and they need to know whether these ports will be TCP, UDP, etc.

是否有命令行技巧来区分此服务器上的开放端口是HTTP还是TCP?我向我的信息技术办公室请求我在这台服务器上需要的端口,他们需要知道这些端口是TCP,UDP等。

If necessary to use a remote client, I have a Mac that can do the job.

如果需要使用远程客户端,我有一台Mac可以完成这项工作。

2 个解决方案

#1


1  

All HTTP traffic is transmitted over TCP Ports. I think what may be causing some confusion is that the first node.js example uses the http module and the second example uses the net module.

所有HTTP流量都通过TCP端口传输。我认为可能导致一些混淆的是第一个node.js示例使用http模块,第二个示例使用net模块。

The http module is built on top of the net module (which handles the TCP layer underlying HTTP).

http模块构建在net模块之上(处理基础HTTP的TCP层)。

Refer to: nodejs - net or http module

请参阅:nodejs - net或http模块

EDIT:

编辑:

Only one process can bind to a port. If you're having difficulties connecting, shut down any other applications that may be using the same port, such as your Java Hello World server. Run netstat -an to make sure you don't see the port listed that you're trying to listen on in you node.js TCP server (port 1337) in the example. If nothing is listening on the port, fire up your node.js TCP server and run netstat -an again to make sure it's actually listening on the intended port.

只有一个进程可以绑定到端口。如果您在连接时遇到困难,请关闭可能使用相同端口的任何其他应用程序,例如Java Hello World服务器。运行netstat -an以确保您没有在示例中的node.js TCP服务器(端口1337)中看到您尝试侦听的端口。如果没有正在侦听端口,请启动node.js TCP服务器并再次运行netstat -an以确保它实际上正在侦听预期的端口。

Another suggestion - temporarily turn off the software firewall then use the telnet client on the local server to attempt to connect to the port using the command telnet 127.0.0.1 1337 (replace 1337 with your port) from the command prompt. This will eliminate any network devices such as firewalls between the client (telnet in this case) and the server. If the screen goes blank, you've connected. If you get the message Could not open connection to the host, on port then it's still not listening on the TCP Port. If you can connect locally from Telnet but you cannot connect remotely then there is something blocking your connection.

另一个建议 - 暂时关闭软件防火墙,然后使用本地服务器上的telnet客户端尝试使用命令telnet 127.0.0.1 1337(用您的端口替换1337)连接到端口。这将消除客户端(本例中为telnet)与服务器之间的任何网络设备,如防火墙。如果屏幕变为空白,则表示已连接。如果您收到消息无法打开与主机的连接,则在端口上它仍然没有在TCP端口上侦听。如果您可以从Telnet本地连接,但无法远程连接,则会阻止您的连接。

#2


2  

HTTP is an application protocol. Its definition presumes an underlying and reliable transport layer protocol. The transmission Control Protocol is commonly used. However HTTP can use unreliable protocols too (example SSDP).

HTTP是一种应用程序协议。它的定义假定了一个潜在的,可靠的传输层协议。通常使用传输控制协议。但是HTTP也可以使用不可靠的协议(例如SSDP)。

Now to answer to your question:

现在回答你的问题:

  • netstat -lt : List TCP Listening Ports
  • netstat -lt:列出TCP侦听端口
  • netstat -lu : List UDP Listening Ports
  • netstat -lu:列出UDP侦听端口

If you want to know wether a TCP Port is running HTTP or not, you can check the standard port on HTTP (grep :80). The standard HTTP port is 80. The standard HTTPS port is 443.

如果您想知道TCP端口是否正在运行HTTP,您可以检查HTTP上的标准端口(grep:80)。标准HTTP端口为80.标准HTTPS端口为443。

#1


1  

All HTTP traffic is transmitted over TCP Ports. I think what may be causing some confusion is that the first node.js example uses the http module and the second example uses the net module.

所有HTTP流量都通过TCP端口传输。我认为可能导致一些混淆的是第一个node.js示例使用http模块,第二个示例使用net模块。

The http module is built on top of the net module (which handles the TCP layer underlying HTTP).

http模块构建在net模块之上(处理基础HTTP的TCP层)。

Refer to: nodejs - net or http module

请参阅:nodejs - net或http模块

EDIT:

编辑:

Only one process can bind to a port. If you're having difficulties connecting, shut down any other applications that may be using the same port, such as your Java Hello World server. Run netstat -an to make sure you don't see the port listed that you're trying to listen on in you node.js TCP server (port 1337) in the example. If nothing is listening on the port, fire up your node.js TCP server and run netstat -an again to make sure it's actually listening on the intended port.

只有一个进程可以绑定到端口。如果您在连接时遇到困难,请关闭可能使用相同端口的任何其他应用程序,例如Java Hello World服务器。运行netstat -an以确保您没有在示例中的node.js TCP服务器(端口1337)中看到您尝试侦听的端口。如果没有正在侦听端口,请启动node.js TCP服务器并再次运行netstat -an以确保它实际上正在侦听预期的端口。

Another suggestion - temporarily turn off the software firewall then use the telnet client on the local server to attempt to connect to the port using the command telnet 127.0.0.1 1337 (replace 1337 with your port) from the command prompt. This will eliminate any network devices such as firewalls between the client (telnet in this case) and the server. If the screen goes blank, you've connected. If you get the message Could not open connection to the host, on port then it's still not listening on the TCP Port. If you can connect locally from Telnet but you cannot connect remotely then there is something blocking your connection.

另一个建议 - 暂时关闭软件防火墙,然后使用本地服务器上的telnet客户端尝试使用命令telnet 127.0.0.1 1337(用您的端口替换1337)连接到端口。这将消除客户端(本例中为telnet)与服务器之间的任何网络设备,如防火墙。如果屏幕变为空白,则表示已连接。如果您收到消息无法打开与主机的连接,则在端口上它仍然没有在TCP端口上侦听。如果您可以从Telnet本地连接,但无法远程连接,则会阻止您的连接。

#2


2  

HTTP is an application protocol. Its definition presumes an underlying and reliable transport layer protocol. The transmission Control Protocol is commonly used. However HTTP can use unreliable protocols too (example SSDP).

HTTP是一种应用程序协议。它的定义假定了一个潜在的,可靠的传输层协议。通常使用传输控制协议。但是HTTP也可以使用不可靠的协议(例如SSDP)。

Now to answer to your question:

现在回答你的问题:

  • netstat -lt : List TCP Listening Ports
  • netstat -lt:列出TCP侦听端口
  • netstat -lu : List UDP Listening Ports
  • netstat -lu:列出UDP侦听端口

If you want to know wether a TCP Port is running HTTP or not, you can check the standard port on HTTP (grep :80). The standard HTTP port is 80. The standard HTTPS port is 443.

如果您想知道TCP端口是否正在运行HTTP,您可以检查HTTP上的标准端口(grep:80)。标准HTTP端口为80.标准HTTPS端口为443。