Check Connection established on a TCP port from a program?

Network monitoring
Is there any way to get the status of a TCP port within a program? We need to monitor a specific port to ensure that a communications link is established, and then send a page to the analyst on call when the communications link goes down. I can view the information with NETSTAT 3 (WRKTCPSTS *CNN), but I need to create a never ending batch process to do the monitoring. Any help would be appreciated.

Answer Wiki

Thanks. We'll let you know when a new response is added.

You should be able to do that using WMI. Have a look at the Win32_SystemNetworkConnections and Win32_NetworkConnection classes.

Discuss This Question: 4  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Ttrish
    You might try looking at API QTocRtvNetCnnDta (Retrieve Network Connection Data)in IBM's Information Centre
    0 pointsBadges:
  • Mschoenb2005
    WhatsUp Gold is a good inexpensive application that you can purchase that will handle this. Its good in a Windows environment although you can measure any platform with it via SNMP. Nagios is a good Unix Base application. I believe it is freeware.
    0 pointsBadges:
  • Donjohn
    ttrish is right. Just about the only way you can recreate the functionality of netstat option 3 is by calling the API of QTocRtvNetCnnDta....however, Im not that strong with API programming.... ttrish, can u send us a sample source code that will call this API?
    10 pointsBadges:
  • TomLiotta
    What do you mean by "monitoring"? If there's a program communicating through the port, it knows if it's communicating or not. What are you expecting something outside the program to do that the program can't do easier? And what do you mean by "communications link"? The internet? Or do you have a modem/point-to-point connection or similar? Please provide some info on what the process is. It's far too vague so far. The QTocRtvNetCnnDta API might be appropriate, but there's no way to know from the info so far. And it's not a trivial API, especially if you don't already know sockets programming to help interpret the results. Connections come and go all the time. You don't want to be alerting an admin every 20 minutes for no good reason. Tom
    125,585 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: