以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何判断指定端口是否有效,是否被占用?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=107080)

--  作者:pcxjxjhkw
--  发布时间:2017/9/21 8:40:00
--  [求助]如何判断指定端口是否有效,是否被占用?
如题,谢谢
--  作者:有点甜
--  发布时间:2017/9/21 9:29:00
--  

方法一

 

Dim hl As new Net.HttpListener
try
    hl.Prefixes.Add("http://*:80/")
    hl.start
catch ex As exception
    msgbox("被占用了")
finally
    hl.close
End try


--  作者:有点甜
--  发布时间:2017/9/21 9:33:00
--  

方法二

 

Dim IPs = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties
Dim ipEndPoints = ips.GetActiveTcpListeners
Dim inUse As Boolean = False
For Each endPoint As object In ipEndPoints
    If endPoint.Port = 80 Then
        inUse = True
        Exit For
    End If
Next

Return inUse


--  作者:pcxjxjhkw
--  发布时间:2017/9/21 9:50:00
--  
谢谢