vb.net - 获取当前使用指定端口号的IP地址
问题描述
我在 vb.net 中有一个简单的 TCP 客户端-服务器设置。我想知道是否可以返回当前使用指定端口号的所有IP地址,我将如何处理?
解决方案
这里是翻译自IPGlobalProperties.GetActiveTcpConnections Method的 VB.NET 解决方案。
Imports System.Net.NetworkInformation
Module Module1
Sub Main()
ShowActiveTcpConnections()
End Sub
Public Sub ShowActiveTcpConnections()
Debug.WriteLine("Active TCP Connections")
Dim properties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties
Dim connections() As TcpConnectionInformation = properties.GetActiveTcpConnections
For Each c As TcpConnectionInformation In connections
Debug.WriteLine("{0} <==> {1}", c.LocalEndPoint.ToString, c.RemoteEndPoint.ToString)
Next
End Sub
End Module
输出示例:
Active TCP Connections
127.0.0.1:1028 <==> 127.0.0.1:5354
127.0.0.1:1029 <==> 127.0.0.1:5354
127.0.0.1:1055 <==> 127.0.0.1:27015
127.0.0.1:1069 <==> 127.0.0.1:27015
127.0.0.1:1071 <==> 127.0.0.1:27015
127.0.0.1:1080 <==> 127.0.0.1:27015
127.0.0.1:1081 <==> 127.0.0.1:5354
127.0.0.1:1082 <==> 127.0.0.1:5354
127.0.0.1:1084 <==> 127.0.0.1:1085
127.0.0.1:1085 <==> 127.0.0.1:1084
127.0.0.1:1154 <==> 127.0.0.1:27015
127.0.0.1:5354 <==> 127.0.0.1:1028
推荐阅读
- stripe-payments - Stripe Checkout 服务器端加载客户卡
- javascript - 使用 NodeJS 通过 LDAP 身份验证获取用户个人资料图片
- java - MismatchedInputException - Jackson 反序列化
- pipeline - 在 pdal 管道文件中读入和合并多个 .las
- php - 我在使用 xamp 的本地主机中遇到 codeigniter 错误
- python - 查找图像每个部分的平均颜色
- c# - 列表上的动态查询选择包含列表
- ios - 如何仅重新加载 tableView 部分标题?
- python - 为什么 type(((),)[0]) 是元组而不是 int?
- javascript - 我正在尝试绘制随机数,直到找到某个数字,但为什么我的 for 循环计数器不起作用?