Parse:...solaris(3pm)
π Parse::Netstat::solaris β the manual, but make it make sense π
okay bestie, gather round π«Ά this is Parse::Netstat::solaris, a lil module from the Parse::Netstat Perl distribution, and its whole entire job is taking the raw output of the Solaris netstat command and turning it into actual structured data you can use. no cap. it's giving "I read the chaos so you don't have to" energy and honestly? iconic. β¨
π NAME
Parse::Netstat::solaris β parses the output of the Solaris netstat command. that's it, that's the gig, and it does it flawlessly. π
πΈ VERSION
this doc describes version 0.150 of Parse::Netstat::solaris, which ships in the Perl distribution Parse-Netstat, released on 2022-12-04. so yeah, it's been out here thriving. π¦
β¨ SYNOPSIS
here's the whole vibe in two lines:
use Parse::Netstat qw(parse_netstat);
my $res = parse_netstat(output=>join("", `netstat -n`), flavor=>"solaris");
and here's a sample netstat -n output so you can see what kind of chaos we're parsing β UDP first, then TCP, then a whole crowd of UNIX domain sockets:
UDP: IPv4
Local Address Remote Address State
-------------------- -------------------- ----------
8.8.17.4.15934 8.8.7.7.53 Connected
127.0.0.1.32859 127.0.0.1.514 Connected
127.0.0.1.32860 127.0.0.1.514 Connected
TCP: IPv4
Local Address Remote Address Swind Send-Q Rwind Recv-Q State
-------------------- -------------------- ----- ------ ----- ------ -----------
8.8.17.4.1337 8.8.213.120.65472 262140 0 1049920 0 ESTABLISHED
8.8.17.4.44306 8.8.17.4.111 57304 0 1055220 0 TIME_WAIT
8.8.17.4.44064 8.8.17.4.32774 57260 0 1055220 0 TIME_WAIT
8.8.17.4.44308 8.8.17.4.32774 57260 0 1055220 0 TIME_WAIT
8.8.17.4.44066 8.8.17.4.111 57304 0 1055220 0 TIME_WAIT
8.8.17.4.44310 8.8.17.4.111 57304 0 1055220 0 TIME_WAIT
Active UNIX domain sockets
Address Type Vnode Conn Local Addr Remote Addr
30258256428 stream-ord 00000000 00000000
30575aa2b38 stream-ord 00000000 00000000
305744acaf8 stream-ord 00000000 00000000
30575aa3b88 stream-ord 00000000 00000000
3013c427d68 stream-ord 00000000 00000000
303b66230f8 stream-ord 00000000 00000000
3042fbbb228 stream-ord 30b59894f40 00000000 /tmp/ssh-MyY25402/agent.25402
30186d43d70 stream-ord 00000000 00000000
303e8e332f8 stream-ord 00000000 00000000
3049e75ece0 stream-ord 302d8344500 00000000 /var/tmp/amavisd-new/abgeber/amavisd.sock
3049e75f250 stream-ord 00000000 00000000
and here's the sample result β look at that beautiful nested data structure, she ate π :
[
200,
"OK",
{
active_conns => [
{},
{
foreign_host => "8.8.7.7",
foreign_port => 53,
local_host => "8.8.17.4",
local_port => 15934,
proto => "udp4",
state => "Connected",
},
{
foreign_host => "127.0.0.1",
foreign_port => 514,
local_host => "127.0.0.1",
local_port => 32859,
proto => "udp4",
state => "Connected",
},
{
foreign_host => "127.0.0.1",
foreign_port => 514,
local_host => "127.0.0.1",
local_port => 32860,
proto => "udp4",
state => "Connected",
},
{},
{
foreign_host => "8.8.213.120",
foreign_port => 65472,
local_host => "8.8.17.4",
local_port => 1337,
proto => "tcp4",
recvq => 0,
rwind => 1049920,
sendq => 0,
state => "ESTABLISHED",
swind => 262140,
},
{
foreign_host => "8.8.17.4",
foreign_port => 111,
local_host => "8.8.17.4",
local_port => 44306,
proto => "tcp4",
recvq => 0,
rwind => 1055220,
sendq => 0,
state => "TIME_WAIT",
swind => 57304,
},
{
foreign_host => "8.8.17.4",
foreign_port => 32774,
local_host => "8.8.17.4",
local_port => 44064,
proto => "tcp4",
recvq => 0,
rwind => 1055220,
sendq => 0,
state => "TIME_WAIT",
swind => 57260,
},
{
foreign_host => "8.8.17.4",
foreign_port => 32774,
local_host => "8.8.17.4",
local_port => 44308,
proto => "tcp4",
recvq => 0,
rwind => 1055220,
sendq => 0,
state => "TIME_WAIT",
swind => 57260,
},
{
foreign_host => "8.8.17.4",
foreign_port => 111,
local_host => "8.8.17.4",
local_port => 44066,
proto => "tcp4",
recvq => 0,
rwind => 1055220,
sendq => 0,
state => "TIME_WAIT",
swind => 57304,
},
{
foreign_host => "8.8.17.4",
foreign_port => 111,
local_host => "8.8.17.4",
local_port => 44310,
proto => "tcp4",
recvq => 0,
rwind => 1055220,
sendq => 0,
state => "TIME_WAIT",
swind => 57304,
},
{},
{
address => 30258256428,
conn => "00000000",
proto => "unix",
type => "stream-ord",
vnode => "00000000",
},
{
address => "30575aa2b38",
conn => "00000000",
proto => "unix",
type => "stream-ord",
vnode => "00000000",
},
{
address => "305744acaf8",
conn => "00000000",
proto => "unix",
type => "stream-ord",
vnode => "00000000",
},
{
address => "30575aa3b88",
conn => "00000000",
proto => "unix",
type => "stream-ord",
vnode => "00000000",
},
{
address => "3013c427d68",
conn => "00000000",
proto => "unix",
type => "stream-ord",
vnode => "00000000",
},
{
address => "303b66230f8",
conn => "00000000",
proto => "unix",
type => "stream-ord",
vnode => "00000000",
},
{
address => "3042fbbb228",
conn => "00000000",
local_addr => "/tmp/ssh-MyY25402/agent.25402",
proto => "unix",
type => "stream-ord",
vnode => "30b59894f40",
},
{
address => "30186d43d70",
conn => "00000000",
proto => "unix",
type => "stream-ord",
vnode => "00000000",
},
{
address => "303e8e332f8",
conn => "00000000",
proto => "unix",
type => "stream-ord",
vnode => "00000000",
},
{
address => "3049e75ece0",
conn => "00000000",
local_addr => "/var/tmp/amavisd-new/abgeber/amavisd.sock",
proto => "unix",
type => "stream-ord",
vnode => "302d8344500",
},
{
address => "3049e75f250",
conn => "00000000",
proto => "unix",
type => "stream-ord",
vnode => "00000000",
},
],
},
]
π οΈ FUNCTIONS
π parse_netstat
Usage:
parse_netstat(%args) -> [$status_code, $reason, $payload, \%result_meta]
basically: this function parses the output of the Solaris netstat command. π«Ά
now, important tea β β netstat can be called with -n (which shows you raw IP addresses and port numbers instead of hostnames or port names) or without it. it can also be called with the -a option (show all listening and non-listening socket) or without it. so like, your mileage in terms of what the output looks like can vary, and this function handles it.
heads up bestie: this function is not exported by default, but it is exportable. so ask for it by name. π
Arguments β and the * means it's required, so don't come to the function without it:
output*=> str β the output of the netstat command. this is the whole meal, you gotta bring it.tcp=> bool (default: 1) β whether to parse TCP (and TCP6) connections. defaults to yes, because of course.udp=> bool (default: 1) β whether to parse UDP (and UDP6) connections. also defaults to yes. we love a generous default.unix=> bool (default: 1) β whether to parse Unix socket connections. again, default yes. slay.
Returns an enveloped result β which is an array, and here's how to read it:
- first element (
$status_code) is an integer holding an HTTP-like status code.200means OK,4xxmeans caller error,5xxmeans function error. - second element (
$reason) is a string with the error message, or something like"OK"if the status is 200. - third element (
$payload) is the actual result β but usually it's not present when the enveloped result is an error response (aka when$status_codeisn't 2xx). - fourth element (
%result_meta) is called result metadata and it's optional β a hash holding extra info, much like how HTTP response headers give you additional metadata.
Return value: (any) β yeah, it's anything, live your truth. β¨
π HOMEPAGE
go visit the project's homepage, bestie, it's right here: <https://metacpan.org/release/Parse-Netstat> π
π¦ SOURCE
the source repository lives at <https://github.com/perlancar/perl-Parse-Netstat> β go peek, it's not weird, it's research. π₯
βοΈ AUTHOR
perlancar <perlancar@cpan.org> β the legend themselves. π
π«Ά CONTRIBUTING
wanna help out? say less. you can send patches by email/via RT, or send pull requests on GitHub. π
and here's the thing β most of the time you genuinely do not need to build the distribution yourself. you can just modify the code and then test it with:
% prove -l
but if you do want to build the distribution (like, say, to try installing it locally on your system), you'll want to 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 you can report that to perlancar. so if you hit extra steps, that's not you being bad at this, that's a bug fr fr. π
Β©οΈ COPYRIGHT AND LICENSE
this software is copyright (c) 2022, 2017, 2015, 2014, 2012, 2011 by perlancar <perlancar@cpan.org>.
and it's free software π β you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. periodt.
π BUGS
found a bug? want a feature? please report any bugs or feature requests on the bugtracker website: <https://rt.cpan.org/Public/Dist/Display.html?Name=Parse-Netstat> π¦
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. it makes everything so much easier and honestly it's the polite thing to do. π
and that's the whole page, bestie!! πΈ this was Parse::Netstat::solaris, documented as Parse:...solaris(3pm) in perl v5.36.0, dated 2023-01-15, from the User Contributed Perl Documentation. go forth and parse those sockets, you absolute icon. π
β¨π
π¦ 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