home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5391 < prev    next >
Encoding:
Internet Message Format  |  1992-08-19  |  3.7 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!swrinde!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!eagle!sandman.lerc.nasa.gov!drich
  2. From: drich@sandman.lerc.nasa.gov (Daniel Rich)
  3. Newsgroups: comp.lang.perl
  4. Subject: Help with perl/chat2
  5. Message-ID: <1992Aug19.204344.28684@eagle.lerc.nasa.gov>
  6. Date: 19 Aug 92 20:43:44 GMT
  7. Sender: news@eagle.lerc.nasa.gov
  8. Organization: NASA Lewis Research Center [Cleveland, Ohio]
  9. Lines: 111
  10. Nntp-Posting-Host: sandman.lerc.nasa.gov
  11.  
  12.  
  13. Some time ago, I asked for help in getting a perl script that would
  14. talk to sendmail.  First of all, thank you to everyone who responded.
  15. I think I got 8-10 different ways of either connecting to sendmail, or
  16. replacing it with a perl script.
  17.  
  18. Anyway, I received one script which does almost exactly what I need,
  19. and I have hacked it (I thought) the rest of the way.  Unfortunatly,
  20. it doesn't work.  I can't figure out what is going wrong from the
  21. documentation in chat2.pl, so I thought I would as the net (if nothing
  22. else, I am guaranteed to get a bunch of people telling me I am not
  23. much of a perl programmer :-).
  24.  
  25. The idea behind this is that I can type "addrcheck user@host" and have
  26. it validate that the user exists on that host (using the SMTP VRFY
  27. command).
  28.  
  29. The script is included below.  When I run it, it seems to connect to
  30. the remote sendmail correctly, but always comes back with the message:
  31. BAD : username: VRFY timeout with hostname ()
  32. (replace the username and hostname with the ones I gave it on the
  33. command line).
  34.  
  35. Can anyone offer any suggestions?  I have tested this under perl
  36. 4.0.1.6 patchlevel 19, and perl 4.0.1.7 patchlevel 35.  At this point,
  37. I am not even sure if the VRFY command is getting to the remote
  38. sendmail (actually, I am assuming it isn't, but I don't have any way
  39. of monitoring the port).
  40.  
  41. Thanks.
  42.  
  43. 8<------------------------------ Cut Here ------------------------------>8
  44. #!/usr/local/bin/perl
  45. #
  46. # $Id$
  47. # addrcheck - connect to remote smtp and validate mail address
  48. #
  49. # $Log$
  50. #
  51.  
  52. require('chat2.pl');
  53.  
  54. $timeout = 20;            # seconds to timeout
  55. $cr = '\r?\n';            # End of line match
  56.  
  57. ($n, $a, $port, $servproto) = getservbyname ('smtp', 'tcp');
  58. if ($port == 0) {
  59.     warn "smtp port not available\n";
  60.     exit;
  61. }
  62.  
  63. while (@ARGV) {
  64.     chop;
  65.     $found = "false";
  66.     $addr = shift @ARGV;
  67.     printf "    : Validating %s...\n",$addr;
  68.  
  69.     while ($found eq "false") {
  70.     ($user, $host) = split('@', $addr);
  71.  
  72.     printf "    :   Checking %s at %s...\n",$user,$host;
  73.  
  74.     if (! ($sendmail = &chat'open_port($host, $port)))
  75.     {
  76.         warn "BAD : $user: open failed with $host ($!)\n";
  77.         last;
  78.     }
  79.     
  80.     if (! &chat'expect($sendmail, $timeout, '^220.*$cr', '1'))
  81.     {
  82.         warn "WARN: $user: greeting timeout with $host ($!)\n";
  83.         &chat'close($sendmail);
  84.         last;
  85.     }
  86.  
  87.     &chat'print($sendmail, 'VRFY $user\r\n');
  88.  
  89.     if (! ($result = &chat'expect($sendmail, $timeout,
  90.          '^([0-9][0-9][0-9].*)$cr', '$1')))
  91.     {
  92.         print "BAD : $user: VRFY timeout with $host ($!)\n";
  93.         &chat'close($sendmail);
  94.         last;
  95.     }
  96.     
  97.     chop($result);
  98.     if ($result =~ /^250/) {
  99.         $addr2 = ($result =~ /<(.*)>/);
  100.         ($user2, $host2) = split('@', $addr);
  101.     } else {
  102.         print "BAD : $user: $host: $result\n";
  103.         last;
  104.     }
  105.     
  106.     # If host is null, we have a local address
  107.     if ($host2 eq "") {
  108.         $found = "true";
  109.         print "GOOD: $user: $host: $result\n";
  110.         } else {
  111.         printf "Found %s: %s at %s.\n",$user,$host;
  112.         $addr = $addr2;
  113.     }
  114.     }
  115. }
  116. 8<------------------------------ Cut Here ------------------------------>8
  117.  
  118. -- 
  119. Dan Rich                    | drich@lerc.nasa.gov   |  (216) 433-4000
  120. Sr. Systems Engineer        | "Danger, you haven't seen the last of me!"
  121. RMS Technologies, Inc.      |    "No, but the first of you turns my stomach!"
  122. NASA Lewis Research Center  | -- The Firesign Theatre's Nick Danger
  123.