Jump to content

Need help for how to know which program use the port


Recommended Posts

I want to write a program to check port conflicts(a program I use the port 9000 and 9001,before the program run, I want to check the port 9000 and 9001 if is using), a part of program is follow,when port conflicts, I want to tell user which program is using port 9000 or 9001, now I have no idea for to get the port conflicts program name, some one can

help me? thanks a lot!

Func CRMPortCheck()
    
    $Server = @IPAddress1
    $CRMPort1 = "9000"
    $CRMPort2 = "9001"

    TCPStartUp()

    $Socket1 = TCPConnect( $Server, $CRMPort1 )
    $Socket2 = TCPConnect( $Server, $CRMPort2 )

    If ($Socket1 = -1) And ($Socket2 = -1) Then 
        Return 0
    Else 
        TCPCloseSocket ($Socket1)
        Return 1
    EndIf

EndFunc
Edited by caocao81
Link to comment
Share on other sites

In your server application, when someone connects to you, send a string identifying the server.

While 1
$ConnectedSocket = TCPAccept( $MainSocket)
If $ConnectedSocket >= 0 Then
    _addclient() ; whatever you do to add the client to a list of clients
    TCPSend($ConnectedSocket, "I am program 1")
    exit
EndIf
Wend

Then on the connecting end (client):

Func CRMPortCheck()
    
    $Server = @IPAddress1
    $CRMPort1 = "9000"
    $CRMPort2 = "9001"

    TCPStartUp()

    $Socket1 = TCPConnect( $Server, $CRMPort1 )
    If Not @error Then Return TCPRecv($Socket1, 100)
    $Socket2 = TCPConnect( $Server, $CRMPort2 )
    If Not @error Then Return TCPRecv($Socket1, 100)
EndFunc

I hope you get the idea.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...