如何知道Linux系统中端口是否打开 [英] How to know if a port is open or not in Linux system
问题描述
我需要查找端口Ex.在Linux系统上打开了端口8080.我正在寻找一个C或C ++ API调用,当给定端口号时,该调用将返回true或false或等效值.这仅需要在本地运行.我不想知道端口上是否有进程在监听,只有防火墙没有阻止它.
I need to find whether a port Ex. port 8080 is opened on a Linux system. I'm looking for a C or C++ API call that will return true or false or the equivalent when given a port number. This only needs to run locally. I don't want to know if there is a process listening on the port, only that is not blocked by the firewall.
我想做的等同于
if( ! IsPortOpen(8080))
cout << "please request IT to open port 8080 before running this tool";
exit(1);
}
推荐答案
我假设您正在本地计算机上寻找开放端口.有很多工具可以做到这一点.
I assume you are looking for open ports on the local machine. There are a lot of tools to do this.
更容易使用和理解的一个是
One of the easier to use and understand is
lsof -i
对于远程计算机,请尝试nmap
或更简单,更基础的netcat
.例如
For remote machines, try nmap
or even easier and more basic netcat
. For example
netcat targetHost 8080
这篇关于如何知道Linux系统中端口是否打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!