热门文章 | 热门软件| 热门源码 | 热门电影 | 知识库 | 联系我们
软件 源码 教程 影视 健康 招聘
  HTML | JavaScript | ASP | PHP | JSP | NET | VB | VC | VF | Windows | Linux | Mysql | Mssql | Oracle | Struts 
当前位置: 创世纪计算机资源网 -> 文章频道 ->vb 
站内搜索:
判断一个TCP/IP端口是否正在使用
作者:佚名 来源:不详 整理日期:2007-4-14

Private Function PortInUse(ByVal PortNumber As Integer) As _
   Boolean
*********************************************
PURPOSE: Determine if a TCP/IP port is in use
EXAMPLE:
    If PortInUse(21) Then
    MsgBox "The standard FTP port is in use on this machine"
    end if
**********************************************
Dim oSocket As Object
Dim bAns As Boolean

On Error Resume Next
Set oSocket = CreateObject("MSWinsock.Winsock.1")
   
    If Err.Number > 0 Then
        Err.Raise 30000, , "Could not create winsock object"
        Exit Function
    End If
   
Err.Clear

oSocket.LocalPort = PortNumber
oSocket.Listen

if we get this error, it means
port is busy
bAns = Err.Number = 10048
oSocket.Close
Set oSocket = Nothing
PortInUse = bAns

End Function

相关文章