简体   繁体   English

如何确定网络连接正在使用哪个端口?

[英]How can I determine which port a network connection is using?

如何查询Windows以确定每个连接在C ++中使用哪个端口?

Have you tried getting the TCP table? 您是否尝试过获取TCP表?

You can ask windows for a table of all TCP connections which shows you the local address, the local port, the remote address, the remote port, and the process ID of the program that has that connection. 您可以向窗口询问所有TCP连接的表,该表向您显示本地地址,本地端口,远程地址,远程端口以及具有该连接的程序的进程ID。

Getting The Table: http://msdn.microsoft.com/en-us/library/windows/desktop/bb408406(v=vs.85).aspx 获取表: http : //msdn.microsoft.com/zh-cn/library/windows/desktop/bb408406(v=vs.85).aspx

Table Entry: http://msdn.microsoft.com/en-us/library/windows/desktop/bb485761(v=vs.85).aspx 表条目: http : //msdn.microsoft.com/zh-cn/library/windows/desktop/bb485761( v= vs.85).aspx

I won't try to make an example because there's a nice one at the first link. 我不会尝试举一个例子,因为在第一个链接中有一个不错的例子。 There's the equivalent for UDP as well should you need both types of connections. 如果您需要两种类型的连接,UDP也具有相同的含义。

您可以通过使用getsockname()API查询套接字绑定到的端口,然后检查sockaddr_in结构的sin_port字段。

You can use the command netstat -b -a on Windows. 您可以在Windows上使用命令netstat -b -a If you must, this could be called as a SHELL call. 如果需要,可以将其称为SHELL调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确定网络堆栈何时准备好再次打开同一主机/端口的套接字? - How can I determine when the network stack is ready to open socket to same host/port again? 如何使用Windows API检查网络连接类型? - How can I check the network connection type using the Windows API? 如何检查哪个进程正在使用 ip/port? - How can I check which process is using an ip/port? 如何检查 qml 上的网络连接? - How can i check network connection on qml? 如何使用Win32 API在给定端口名称的情况下获取网络打印机的IP地址? - How can I get the IP address of a network printer given the port name using the Win32 API? 如何确定正在使用哪个USB端口? - How to determine which USB port is being used? 我如何以编程方式确定网络适配器是否在Windows上是虚拟的? - How can i programatically determine if a Network Adapter is virtual on Windows? 如何使用带有共享指针的Boost Asio来解决“本地网络中止的网络连接”问题? - How can I get around this “Network connection aborted by local system” using Boost Asio with a shared pointer? 如何确定传入连接是否需要SSL? - How can I determine whether an incoming connection is expecting SSL? 如何确定我正在编译的MacOS版本? - How can I determine which version of MacOS I'm compiling on?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM