Parse::Netstat3pm
Parse the output of "netstat" command
Usage
use Parse::Netstat qw(parse_netstat);my $res = parse_netstat(output => join("", `netstat -anp`), flavor=>'linux');
Version
This document describes version 0.150 of Parse::Netstat (from Perl distribution Parse-Netstat), released on 2022-12-04.
Functions
parse_netstat
Usage:
parse_netstat(%args) -> [$status_code, $reason, $payload, \%result_meta]
Parse the output of "netstat" command.
This utility support several flavors of netstat. The default flavor is "linux". Use "--flavor" to select which flavor you want.
Since different flavors provide different fields and same-named fields might contain data in different format, and also not all kinds of possible output from a single flavor are supported, please see the sample parse output for each flavor (in corresponding "Parse::Netstat::*" per-flavor module) you want to use and adjust accordingly.
This function is not exported by default, but exportable.
Arguments ('*' denotes required arguments):
- •
-
flavor=> str (default: "linux")Flavor of netstat.
- •
-
output* => strOutput of netstat command.
This utility only parses program's output. You need to invoke "netstat" on your own.
- •
-
tcp=> bool (default: 1)Parse TCP connections.
- •
-
udp=> bool (default: 1)Parse UDP connections.
- •
-
unix=> bool (default: 1)Parse Unix socket connections.
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
Homepage
Please visit the project's homepage at <https://metacpan.org/release/Parse-Netstat>.
Source
Source repository is at <https://github.com/perlancar/perl-Parse-Netstat>.
Contributor
Steven Haryanto <[email protected]>
Contributing
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
Copyright and license
This software is copyright (c) 2022, 2017, 2015, 2014, 2012, 2011 by perlancar <[email protected]>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Releases
6 releases since Debian 8 (Jessie); the text changed 4 times.