Question : Visual Basic 6 -- How to check if port is 'established' with Winsock or an alternative?

Basically I have a program that needs to check if its a port is established to a IP/server. It's using old VB6 coding right now.. So hopefully there is a way to do it.

Similar to doing a netstat /a for example, you'd get something like  
TCP    83.188.245.170:53954   c-24-98-162-231:2544   ESTABLISHED


So you know it is actually connected to a server. I can check the server port to see if its connected, but sometimes I'm not actually connected to the server but the server is UP. Basically, I need to check if I am connected to determine to reboot my application or not.

Is this possible? If so, how? Thanks! All I need is even a simple way to check if its open/closed/etc. I know there is winsock, but I'm not sure how I can use it to check a LOCALPORT if its connected/established.

The thing is, I KNOW you can check using a winsock.listen on port 53954.. But the port changes when you reconnect since its just a basic 'established' port. So I'd need to get the current IP its on or something like that..

Answer : Visual Basic 6 -- How to check if port is 'established' with Winsock or an alternative?

what i would do is calling netstat from the vb6 code using Shell and log the output to some result file, then parse it and get the information i need about the ports:

for example, for port 443:

Dim RetVal
RetVal = Shell("netstat -an | find ":443" > c:\temp\netstat.log", 1)

the output file should look something like this:

  TCP    0.0.0.0:443            0.0.0.0:0              LISTENING
  TCP    172.20.1.78:37623      216.166.12.33:443      ESTABLISHED
  TCP    172.20.1.78:37625      216.166.12.33:443      ESTABLISHED
  TCP    172.20.1.78:37629      216.166.12.33:443      ESTABLISHED
  TCP    172.20.1.78:37630      216.166.12.33:443      ESTABLISHED
  TCP    172.20.1.78:37648      216.166.12.33:443      ESTABLISHED
  TCP    172.20.1.78:37649      216.166.12.33:443      ESTABLISHED
  TCP    [::]:443               [::]:0                 LISTENING
Random Solutions  
 
programming4us programming4us