jepri has asked for the wisdom of the Perl Monks concerning the following question:

I just wrote a little program that displays all current connections in a window using perl/Tk. But it shells out to 'netstat' to gather the connection details. Is there a way of getting this info just using perl? I had a look through the CPAN modules but there wasn't anything there. Worse, any solutions like reading /proc/net limit me to only those platforms with a /proc.

And has anyone heard of a way to manipulate these connections? The only realistic answers seem to be either running a proxy or a DNS and allowing/disallowing new connections. Anyone know of a way to stop a connection if you didn't start it?

____________________
Jeremy
I didn't believe in evil until I dated it.

  • Comment on Contolling ports and connections from perl

Replies are listed 'Best First'.
Re: Controlling ports and connections from perl
by setantae (Scribe) on Jan 15, 2001 at 16:21 UTC
      That is indeed what I would like, but is rather restricted in the number of platforms that it will run on. I didn't make it clear above, but my program runs fine on both MSwindows and Linux, and I'm hoping for a Mac OS X port later in the year. Using something restricted to BSD-style kernels would be a step backwards for me.

      Thx anyway :)

      ____________________
      Jeremy
      I didn't believe in evil until I dated it.

        If you want multiplatform process management then the answer to your questions is likely "no".

        The stark fact of the matter is that one of the core differences between platforms is how they manage, control and apply permissions to running processes. Network stacks are even more flaky since a number of platforms have multiple, different IP/network systems that can be installed.

        If you want the fine-grained control you are looking for you will have to get into platform specific code. Consider writing what you are doing as a Module that internally figures out what platform you are running on and calls the proper sub-module that overrides certain methods with platform specific ones. That way you get a single interface around separate platforms.

        --
        $you = new YOU;
        honk() if $you->love(perl)

Re: Contolling ports and connections from perl
by a (Friar) on Jan 16, 2001 at 21:40 UTC