Parse::Netstat(3pm)

πŸ“¦
version 0.150 Β· 2 versions
  • 0.150 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.14 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸŽ€ 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 the netstat command. and bestie, real talk: this utility only parses the program's output. you have to invoke netstat yourself. 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:

  1. first element ($status_code) β€” an integer with an HTTP-like status code (200 means OK, 4xx is a caller error, 5xx is a function error). iykyk.
  2. second element ($reason) β€” a string with the error message, or something like "OK" if the status is 200. slay.
  3. third element ($payload) β€” the actual result. but heads up: usually not present when the enveloped result is an error response (i.e. when $status_code is not 2xx). she's not handing you a payload when things went sideways.
  4. 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-netstat from 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. πŸ’€


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