Monks,

I have a Windows server that has a couple of vital services listening on ports, and I need to make sure they're always around. I don't want to bind to the port, I am happy enough to look at a table of established sockets and check that everything is there.

Were I to backtick a netstat -na -p tcp, I could grovel through the output and look for the established connections on localhost, and ensure that all the ports I'm interested make the roll-call. For instance, if ports 3105 through 3505 are there, everything's groovy:

... TCP 127.0.0.1:3105 127.0.0.1:4317 ESTABLISHED TCP 127.0.0.1:3205 127.0.0.1:4340 ESTABLISHED TCP 127.0.0.1:3305 127.0.0.1:4329 ESTABLISHED TCP 127.0.0.1:3505 127.0.0.1:1974 ESTABLISHED ... lots of other uninteresting lines omitted ...

Before I code up a regexp, I was idly wondering whether there's anything in Win32:: space that will allow to access the underlying information directly. This strikes me as being more elegant, and a shade more efficient to boot (as the server has several thousand sockets open and netstat takes a while to go about its business), rather than scraping netstat. And I'd learn about a new module, which would be a bonus.

• another intruder with the mooring in the heart of the Perl


In reply to Querying established ports on Win32 by grinder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.