#! perl -slw use strict; use Math::Random::MT qw[ rand ]; use Net::CIDR::Lite; use threads; our $WORKERS ||= 10; sub n2ip { join '.', unpack 'C4', pack 'V', $_[ 0 ] } sub worker { my $tid = threads->tid; my $CIDR = shift; for( 1 .. 1000 ) { my $ip = n2ip( int( rand 2**32 ) ); printf "[$tid] $ip was %s\n", $CIDR->find( $ip ) ? 'found' : 'not found'; } } my $CIDR = Net::CIDR::Lite->new( map{ n2ip( int( rand 2**32 ) ) . '/' . ( 1+int( rand 32 ) ) } 1 .. 10 ); print for $CIDR->list; printf "Enter to run threads"; <>; my @threads = map{ threads->create( \&worker, $CIDR ); } 1 .. $WORKERS; $_->join for @threads; __END__ C:\test>CIDR -WORKERS=100 16.0.0.0/4 133.105.224.0/20 155.64.0.0/10 191.83.33.64/26 192.0.0.0/3 224.0.0.0/4 Enter to run threads [1] 133.253.94.106 was not foun [1] 142.170.146.37 was not foun [1] 255.246.52.63 was not found [1] 223.1.163.7 was found [2] 93.38.214.136 was not found [3] 74.172.118.234 was not foun [3] 205.199.108.66 was found [3] 124.251.49.2 was not found [3] 230.87.252.108 was found [3] 195.216.205.202 was found [3] 240.11.9.134 was not found [3] 234.100.16.237 was found [3] 210.137.186.2 was found