ocehb: (Default)
[personal profile] ocehb
для начала -- из range в cidr представление:



function range2cidr () {
    if [[ $# == 3 && $2 == "-" ]]; then
        perl -MNet::CIDR::Lite -le '$cidr = Net::CIDR::Lite->new(@ARGV); print join "\n",$cidr->list' $1-$3
    else
        perl -MNet::CIDR::Lite -le '$cidr = Net::CIDR::Lite->new(@ARGV); print join "\n",$cidr->list' $1
    fi

    return $!
}



использование:


# range2cidr 123.144.0.0 - 123.147.255.255
123.144.0.0/14
# range2cidr 123.144.0.0-123.147.255.255
123.144.0.0/14
#


и сама функция:



function host2block () {
   local i body="$( whois $1 )"

   local ret=$( print "$body" | awk "/^ +Netblock:/ { print \$2 }" )

   if [[ -n $ret ]]; then
        print $ret
        return
   fi

   for i in ${(f)"$( print "$body" | awk '/^inetnum:/ { print $2,"-",$4 }')"}; do
        range2cidr "$i"
   done

   [[ -n $i ]] && return

   print "$body"

   return
}



использование:

# host2block 118.169.82.252
118.169.0.0/16
#
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org

Profile

ocehb: (Default)
ocehb

January 2021

S M T W T F S
     12
345 6789
10111213141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 6th, 2026 04:27 am
Powered by Dreamwidth Studios