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

Anyone can help me with this Perl script?

##this section looks up the DNS host name of a given IP address use Socket; $gothostbyaddr=gethostbyaddr($address, 2); ##this section forms and email and sends use OLE; $Mailer = CreateObject OLE 'SMTPsvg.Mailer'; $Mailer->{'FromName'} = 'whatevername'; $Mailer->{'FromAddress'} = 'whatever@mysite.com'; $Mailer->{'RemoteHost'} = 'websmtp.mysite.com'; $Mailer->AddRecipient('Recipient', 'receipient@yoursite.com'); $Mailer->{'Subject'} = "Title page"; $Mailer->{'BodyText'} = "$address is $gothostbyaddr"; if ($Mailer->SendMail()) { print "Mail successfully sent", "\n"; } else { print $Mailer->{'Response'},"Mail failure. Check mail host server +name and tcp/ip connection...", "\n"; }

Now, the DNS lookup script works fine by itself without the email script, and the email script works fine by itself without the DNS script, but when they're together like above, only the DNS lookup script works, and the mail section returns the "10057 Socket is not connected" error msg.

I suspect that the DNS lookup script using socket to check DNS interferes with the script's ability to access the mail server. My webhosting service is a small company and they don't know PERL.

Anyone has a clue?

Replies are listed 'Best First'.
Re: [10057] socket is not connected error msg
by Preceptor (Deacon) on Oct 07, 2002 at 15:06 UTC
    I haven't tried your script, because OLE is a Win32 thingy and so I can't actually pick up what's wrong. But I'd recommend giving it another try with 'Net::DNS::Resolver'
    use strict; use warnings; use Net::DNS; my $resolver = new Net::DNS::Resolver; my $query = $resolver -> search ( $address ); if ( $query ) { foreach my $RR ( $query -> answer ) { next unless $RR -> type eq "PTR"; print $RR -> rdatastr, "\n"; } }
    A little more heavyweight than 'gethostbyaddr' but if the worst comes to it, then Net::DNS gives error messages for troubleshooting.
    (the print line is there to allow testing. What you'd want to do is change that to '$gothostaddr = $RR -> rdatastr')
    --
    It's not pessimism if there is a worse option, it's not paranoia when they are and it's not cynicism when you're right.