Edwards, Mark (CXO) <mailto:mark.r.edwa...@hp.com> wrote: > I thought of something like that but would rather implement it using > some kind of Perl socket routine. I'll be using this on Windows and > different flavors of Unix and the output format of netstat differs.
It does differ, but not by much in my experience. I expect that it would be simpler to manage the differences in netstat output than the differences in discovering information about open sockets from different operating systems. Those OS differences are (mostly) encapsulated by netstat. For example, the following seems to work on Win32 and Linux. sub tcp_port_state { my $port_to_check = shift; foreach (`netstat -na`) { next unless /tcp/i; my ($local, $state) = get_tcp_fields($_); my $port = (split /:/, $local)[-1]; if ($port == $port_to_check) { return $state; } } return "NOT IN USE"; } sub get_tcp_fields { my @flds = split " ", $_[0]; if ($^O =~ /cygwin|win32/i) { return @flds[1,3]; } else { return @flds[3,5]; } } Also, I notice that there is a module, Net::Netstat::Wrapper, that may be of interest. HTH -- Brian Raven Please consider the environment before printing this e-mail. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs