NAME

Parse::Netstat - Parse the output of "netstat" command

VERSION

version 0.06

SYNOPSIS

use Parse::Netstat qw(parse_netstat parse_netstat_win);

my $output = `netstat -anp`;
my $res = parse_netstat output => $output;

Sample result:

[
 200,
 "OK",
 {
   active_conns => [
     {
       foreign_host => "0.0.0.0",
       foreign_port => "*",
       local_host => "127.0.0.1",
       local_port => 1027,
       proto => "tcp",
       recvq => 0,
       sendq => 0,
       state => "LISTEN",
     },
     ...
     {
       foreign_host => "0.0.0.0",
       foreign_port => "*",
       local_host => "192.168.0.103",
       local_port => 56668,
       proto => "udp",
       recvq => 0,
       sendq => 0,
     },
     ...
     {
       flags   => "ACC",
       inode   => 15631,
       path    => "\@/tmp/dbus-VS3SLhDMEu",
       pid     => 4513,
       program => "dbus-daemon",
       proto   => "unix",
       refcnt  => 2,
       state   => "LISTENING",
       type    => "STREAM",
     },
   ],
 }
]

FUNCTIONS

parse_netstat(%args) -> [status, msg, result, meta]

Parse the output of Unix "netstat" command.

Netstat can be called with -n (show raw IP addresses and port numbers instead of hostnames or port names) or without. It can be called with -a (show all listening and non-listening socket) option or without. And can be called with -p (show PID/program names) or without.

For parsing output of Windows "netstat", see parsenetstatwin().

Arguments ('*' denotes required arguments):

  • output* => str

    Parse the output of Unix "netstat" command.

    Netstat can be called with -n (show raw IP addresses and port numbers instead of hostnames or port names) or without. It can be called with -a (show all listening and non-listening socket) option or without. And can be called with -p (show PID/program names) or without.

    For parsing output of Windows "netstat", see parsenetstatwin().

  • tcp => bool (default: 1)

    Parse the output of Unix "netstat" command.

    Netstat can be called with -n (show raw IP addresses and port numbers instead of hostnames or port names) or without. It can be called with -a (show all listening and non-listening socket) option or without. And can be called with -p (show PID/program names) or without.

    For parsing output of Windows "netstat", see parsenetstatwin().

  • udp => bool (default: 1)

    Parse the output of Unix "netstat" command.

    Netstat can be called with -n (show raw IP addresses and port numbers instead of hostnames or port names) or without. It can be called with -a (show all listening and non-listening socket) option or without. And can be called with -p (show PID/program names) or without.

    For parsing output of Windows "netstat", see parsenetstatwin().

  • unix => bool (default: 1)

    Parse the output of Unix "netstat" command.

    Netstat can be called with -n (show raw IP addresses and port numbers instead of hostnames or port names) or without. It can be called with -a (show all listening and non-listening socket) option or without. And can be called with -p (show PID/program names) or without.

    For parsing output of Windows "netstat", see parsenetstatwin().

Return value:

Returns an enveloped result (an array). First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

parse_netstat_win(%args) -> [status, msg, result, meta]

Parse the output of Windows "netstat" command.

Netstat can be called with -n (show raw IP addresses and port numbers instead of hostnames or port names) or without. It can be called with -a (show all listening and non-listening socket) option or without. It can be called with -o (show PID) or without. And it can be called with -b (show executables) or not.

For parsing output of Unix "netstat", see parse_netstat().

Arguments ('*' denotes required arguments):

  • output* => str

    Parse the output of Windows "netstat" command.

    Netstat can be called with -n (show raw IP addresses and port numbers instead of hostnames or port names) or without. It can be called with -a (show all listening and non-listening socket) option or without. It can be called with -o (show PID) or without. And it can be called with -b (show executables) or not.

    For parsing output of Unix "netstat", see parse_netstat().

  • tcp => bool (default: 1)

    Parse the output of Windows "netstat" command.

    Netstat can be called with -n (show raw IP addresses and port numbers instead of hostnames or port names) or without. It can be called with -a (show all listening and non-listening socket) option or without. It can be called with -o (show PID) or without. And it can be called with -b (show executables) or not.

    For parsing output of Unix "netstat", see parse_netstat().

  • udp => bool (default: 1)

    Parse the output of Windows "netstat" command.

    Netstat can be called with -n (show raw IP addresses and port numbers instead of hostnames or port names) or without. It can be called with -a (show all listening and non-listening socket) option or without. It can be called with -o (show PID) or without. And it can be called with -b (show executables) or not.

    For parsing output of Unix "netstat", see parse_netstat().

Return value:

Returns an enveloped result (an array). First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

SEE ALSO

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Parse-Netstat.

SOURCE

Source repository is at https://github.com/sharyanto/perl-Parse-Netstat.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Parse-Netstat

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.