Hello monks, first of all im a perl begginer so im very limited in writing effective code.
So what i want to do is to scan some ranges of ips, i did this with 4 nested for loops, now i dont want to scan all those ranges inmediately so i wan to limit the calls to the function but dunno how to do it, so lets say i scan 1.1.1.1 to 1.1.1.255, so once entered the loop and when it reaches to 50 calls to the sub i want to stop and then wait for some results the subroutines and the results i have already sorted them out, but cant figure how to limit the loop, i.e every 50 ip's wait for results and then continue, i have tried some approaches but they dont work. I.e ive tried to put a condition and a counter it does stop at 50 but then it will left various ip's without scan, because the counter dont reach the condition .
Now last thing ive tried is this code which actually works nicely, but i wanted to know if theres a cleaner and effective way to do this, if possible not using any additional modules at all?
## will count the number of ipadresses that will be scanned
my $rjob;
{
my $hjobs = 0;
my($i,$j,$k,$l);
for ($l=1;$l<=1;$l++){
for ($i=1;$i<=1;$i++){
for ($j=1;$j<=1;$j++){
for ($k=1;$k<=255;$k++){
$hjobs++;
};
};
};
};
$rjob=$hjobs;
};
print "$rjob\n";
my $maxwork = $ARGV[3] || 50;
{
my $conter=0;
my($i,$j,$k,$l);
for ($l=1;$l<=1;$l++){
for ($i=1;$i<=1;$i++){
for ($j=1;$j<=1;$j++){
for ($k=1;$k<=255;$k++){
$conter++;
$rjob--;
print "$l.$i.$j.$k\n";
if ($rjob < $maxwork && $conter< $maxwork){
if ($rjob==0){
### prints are for testing if the code worked, which did
print "do the work $l.$i.$j.$k $conter $rjob\n";
};
};
if ($conter >= $maxwork){
#sleep 1;
print "$l.$i.$j.$k $conter $rjob\n";
$conter=0;
};
};
};
};
};
};
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.