On 2022-11-14 at 14:09:14 UTC-0500 (Mon, 14 Nov 2022 12:09:14 -0700) Grant Taylor via users <[email protected]> is rumored to have said:
> On 11/11/22 10:10 AM, Bill Cole wrote:
>> From my bashrc...
>>
>> # type cidrcon
>> cidrcon is a function
>> cidrcon ()
>> {
>> for a in $*;
>> do
>> echo $a;
>> done | perl -e "use Net::CIDR::Lite; \$cidr = Net::CIDR::Lite->new(<>)
>> ; \$_ = join (\"\n\",\$cidr->list) ; print \"\$_\n\";"
>> }
>
> Oh ... (minimally) obfuscated Perl one liner.
Not obfuscated, inherently obscure.
>
> N.B. My Perl is rusty.
>
> Let's try deobfuscating and interpreting.
Uh oh. I wrote that *years* ago, and don't recall what I was thinking in the
specific code...
>> use Net::CIDR::Lite;
>
> Load the Net::CIDR::Lite module.
>
>> $cidr = Net::CIDR::Lite->new(<>);
>
> Instantiate an instance of the Net::CIDR::Lite module.
>
> It also looks like you're reading from STDIN via "<>". Is that correct?
Um, well... Yes. I suppose I am. Took me some time to look at that again and
understand it...
The 'for' loop provides STDIN data via a pipe to perl. One command line arg per
line.
> I feel like that's a Perlish short cut to opening the STDIN. I have almost
> always used an "open" statement for such.
Do not overthink my code. I assure you that I did not.
<> in Perl is an operator that returns either each line from STDIN one at a
time (scalar context) or all lines available from STDIN (until eof) as an array
of lines.
>> $_ = join ("\n",$cidr->list);
>
> Set the unnamed variable
Au Contraire!
That's a scalar named '_' (see 'man perlvar')
> to the output of the list output from the Net::CIDR::Lite object using new
> lines.
Correct. NCL->list returns a list of CIDR networks. This joins them all with
linefeeds to get them into one handy scalar. named _
>> print "$_\n";
>
> Print the unnamed variable with a trailing new line.
Yes.
> I /think/.
>
> Am I close?
Yes.
>> Obviously requires Perl and the Net::CIDR::Lite module. I do not recall why
>> the implementation is so weird, but I've been using it for decades(!?)
>
> The deobfuscated code doesn't seem weird to me.
>
> I suspect some of the weirdness comes from transforming it into a one liner
> and escaping things as necessary to pass it from shell to Perl.
>
> I guess it may be a little weird that the cidrcon() shell function takes
> multiple parameters and prints each of them on a line to pass into Perl.
>
> I wonder if it was easier / simpler to do -- what I call -- the rotation
> (from one line with multiple parameters to multiple lines with one parameter)
> in shell than to deal with them in Perl.
I can't even begin to recall.
I wrote it circa 2003 as part of a tool only I haver ever used which transforms
a blocklist in an irregular perverse range format into multiple output formats,
including a consolidated collection of CIDR blocks for a packet filter on an
old Flowpoint router and a BIND zone file. The whole mess included Expect
scripts too...
> Thank you for sharing Bill. -- Your message has been waiting for me to
> read, analyze, assimilate, and reply. ;-)
Always willing to share my shoddy code.
And that's not put-on modesty. I go back into old code myself and wonder WTF I
was thinking and why I didn't do things otherwise. I think I've quite literally
forgotten everything I ever formally learned about programming, and it shows.
--
Bill Cole
[email protected] or [email protected]
(AKA @grumpybozo and many *@billmail.scconsult.com addresses)
Not Currently Available For Hire
signature.asc
Description: OpenPGP digital signature
