Parse::Netstat(3pm)
π Parse::Netstat β the manual, but make it cute π
okay bestie, pull up a chair, because we're talking about Parse::Netstat(3pm) β yes, that's the manual name, we're keeping it, it's iconic β and it's literally the thing that takes your netstat output and makes it make sense. no cap. π
β¨ NAME β¨
Parse::Netstat β parse the output of the netstat command. that's it. that's the whole job. and she does it flawlessly. π
πΈ VERSION πΈ
this document describes version 0.150 of Parse::Netstat (from the Perl distribution Parse-Netstat), released on 2022-12-04. vintage but thriving, periodt. β¨
π¦ SYNOPSIS π¦
the vibe check, in code form:
use Parse::Netstat qw(parse_netstat);
my $res = parse_netstat(output => join("", `netstat -anp`), flavor=>'linux');
look at her. three lines. main character energy. π
π FUNCTIONS π
π parse_netstat
how you call her:
parse_netstat(%args) -> [$status_code, $reason, $payload, \%result_meta]
she parses the output of the netstat command. π§
okay so here's the tea: this utility supports several flavors of netstat, and the default flavor is "linux". use --flavor to pick which one you want, bestie.
and now the important part, so listen up π«Ά β since different flavors give you different fields, and same-named fields might hold data in totally different formats, and also not every possible kind of output from a single flavor is even supported, you should go look at the sample parse output for each flavor you want to use (they live in the corresponding Parse::Netstat::* per-flavor module) and adjust accordingly. it's giving "read the docs before you come for me", lowkey essential.
this function is not exported by default, but it is exportable. so ask nicely with qw(parse_netstat). π
arguments β the * means required, no exceptions β
flavor=> str (default:"linux") β which flavor of netstat we're dealing with. pick your fighter.output* => str β the output of thenetstatcommand. and bestie, real talk: this utility only parses the program's output. you have to invokenetstatyourself. she is not out here running commands for you, she is a parser, not a babysitter. πtcp=> bool (default:1) β parse TCP connections. on by default, as she should be.udp=> bool (default:1) β parse UDP connections. also on by default. we love consistency.unix=> bool (default:1) β parse Unix socket connections. yep, on by default too. the whole squad. π―
the return, aka what you actually get back π
she returns an enveloped result (an array). and it's structured, okay, let me break it down:
- first element (
$status_code) β an integer with an HTTP-like status code (200means OK,4xxis a caller error,5xxis a function error). iykyk. - second element (
$reason) β a string with the error message, or something like"OK"if the status is200. slay. - third element (
$payload) β the actual result. but heads up: usually not present when the enveloped result is an error response (i.e. when$status_codeis not2xx). she's not handing you a payload when things went sideways. - fourth element (
%result_meta) β called result metadata, and it's optional. it's a hash with extra information, much like how HTTP response headers give you additional metadata. very "here's some bonus lore". β¨
return value: (any)
π HOMEPAGE π
come visit the project's homepage at <https://metacpan.org/release/Parse-Netstat>. it's cute, it's informative, it's the whole package. π
π§ SOURCE π§
the source repository lives at <https://github.com/perlancar/perl-Parse-Netstat>. go poke around, it's giving open source excellence. π
π SEE ALSO π
Parse::Netstat::*β for per-flavor notes and sample outputs. seriously, check these, they're the receipts. π§Ύparse-netstatfrom App::ParseNetstat β a CLI for this module. yes, there's a command-line version, she's got range. π
π AUTHOR π
perlancar <perlancar@cpan.org> β the icon, the legend, the moment. π
πΈ CONTRIBUTOR πΈ
Steven Haryanto <stevenharyanto@gmail.com> β contributing to the cause, we love to see it. π«Ά
π¦ CONTRIBUTING π¦
wanna contribute? obsessed. you can send patches by email/via RT, or send pull requests on GitHub. pick your lane, both are valid. β¨
most of the time you don't need to build the distribution yourself. you can literally just modify the code, then test via:
% prove -l
if you do want to build the distribution (like, say, to try installing 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. and listen β any additional steps required beyond that are considered a bug and can be reported to me. so if you're doing extra unexplained steps, that's not you, that's a bug. π
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2022, 2017, 2015, 2014, 2012, 2011 by perlancar <perlancar@cpan.org>. a whole decade-plus of dedication, honestly inspiring. π
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. free as in freedom, bestie. π
π BUGS π
please report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=Parse-Netstat>. don't suffer in silence, that's not the vibe.
and when you submit a bug or a request, please include a test-file or a patch to an existing test-file that illustrates the bug or the desired feature. give her something to work with, she's not a mind reader. π
π okay that's the whole page, bestie! go forth and parse responsibly! π
sign-off time β¨ β this manual page was rendered by perl v5.36.0, dated 2023-01-15, and it's the one and only Parse::Netstat(3pm). stay slaying, and remember: netstat output is only scary until you parse it. ππ
π¦
π¦ where this page comes from
- debian bookworm: libparse-netstat-perl 0.150-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libparse-netstat-perl 0.150-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libparse-netstat-perl 0.150-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libparse-netstat-perl 0.150-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libparse-netstat-perl 0.150-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms