这个代码怎么优化一下
Dim t As String = "TCP" '协议
Dim port0 As Boolean = False
Dim port1 As Boolean = False
Dim port2 As Boolean = False
Dim port3 As Boolean = False
Dim properties As System.Net.NetworkInformation.IPGlobalProperties = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties()
Dim ipendpoints() As System.Net.IPEndPoint
If t = "TCP" Then
ipendpoints = properties.GetActiveTcpListeners()
Else
ipendpoints = properties.GetActiveUdpListeners()
End If
For Each ipendpoint As System.Net.IPEndPoint In ipendpoints
If ipendpoint.Port = 8880 Then
port0 = True
Output.Show( "8880端口使用中")
ElseIf ipendpoint.Port = 8881 Then
port1 = True
Output.Show( "8881端口使用中")
ElseIf ipendpoint.Port = 8882 Then
port2 = True
Output.Show( "8882端口使用中")
ElseIf ipendpoint.Port = 8883 Then
port3 = True
Output.Show( "8883端口使用中")
End If
Next
ipendpoints = Nothing
properties = Nothing
If port0 = False Then
Output.Show( "8880端口启动成功")
HttpServer.Prefixes.Add("http://*:8880/")
HttpServer.Start()
PopMessage("8880端口启动成功,感谢您的使用!","温馨提示",,5)
ElseIf port1 = False Then
Output.Show( "8881端口启动成功")
HttpServer.Prefixes.Add("http://*:8881/")
HttpServer.Start()
PopMessage("8881端口启动成功,感谢您的使用!","温馨提示",,5)
ElseIf port2 = False Then
Output.Show( "8882端口启动成功")
HttpServer.Prefixes.Add("http://*:8882/")
HttpServer.Start()
PopMessage("8882端口启动成功,感谢您的使用!","温馨提示",,5)
ElseIf port3 = False Then
Output.Show( "8883端口启动成功")
HttpServer.Prefixes.Add("http://*:8883/")
HttpServer.Start()
PopMessage("8883端口启动成功,感谢您的使用!","温馨提示",,5)
End If