All pastes #359666 Raw Edit

mbuf

public text v1 · immutable
·published 2007-02-16 23:47 UTC
rendered paste body
#!/usr/bin/perl

sub ip2bits {

    my $arg = $_[0];
    my %subnet_lookup = ( '255' => 8, "254" => 7, "252" => 6,
			  '248' => 5, "240" => 4, "224" => 3,
			  '192' => 2, "128" => 1, "0"   => 0);
    my @list = split(/\./, $arg);

    for ($i=0; $i<4; $i++) {
	my $string = "$list[$i]";
	foreach my $key (keys %subnet_lookup) {
	    my $value = $key;
	    if ("$string" <=> "$value")
		print "$key : $subnet_lookup{$key}\n";
	}
    }

}

ip2bits "255.255.255.0"