Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: optimise code EV Event AnyEvent POE

by Corion (Pope)
on Jun 26, 2012 at 07:18 UTC ( #978345=note: print w/ replies, xml ) Need Help??


in reply to optimise code EV Event AnyEvent POE

Using AnyEvent::DNS, you could parallelize your DNS requests to the various blacklists instead of waiting for the results sequentially.

#!perl -w use strict; use AnyEvent; use AnyEvent::DNS; my %results; my $outstanding = AnyEvent->condvar; for my $domain (<DATA>) { $domain =~ s!\s+$!!; # Fire off a query for this hostname warn "Querying ip(s) for '$domain'"; $outstanding->begin(); AnyEvent::DNS::resolver->resolve ( $domain, "a", sub { $outstanding->end; if( @_ ) { for (@_) { my ($name, $type, $in, $ttl, $ip) = @$_; $results{ $name } ||= []; warn "Response for $name"; push @{$results{ $name }}, $ip; }; } else { warn "No response for $domain"; }; }); }; # Wait for all requests to finish $outstanding->recv; use Data::Dumper; warn Dumper \%results; __DATA__ google.de google.com example.com doesnotexist.local perlmonks.org


Comment on Re: optimise code EV Event AnyEvent POE
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978345]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-12-26 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls