home *** CD-ROM | disk | FTP | other *** search
- 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
- From: drich@sandman.lerc.nasa.gov (Daniel Rich)
- Newsgroups: comp.lang.perl
- Subject: Help with perl/chat2
- Message-ID: <1992Aug19.204344.28684@eagle.lerc.nasa.gov>
- Date: 19 Aug 92 20:43:44 GMT
- Sender: news@eagle.lerc.nasa.gov
- Organization: NASA Lewis Research Center [Cleveland, Ohio]
- Lines: 111
- Nntp-Posting-Host: sandman.lerc.nasa.gov
-
-
- Some time ago, I asked for help in getting a perl script that would
- talk to sendmail. First of all, thank you to everyone who responded.
- I think I got 8-10 different ways of either connecting to sendmail, or
- replacing it with a perl script.
-
- Anyway, I received one script which does almost exactly what I need,
- and I have hacked it (I thought) the rest of the way. Unfortunatly,
- it doesn't work. I can't figure out what is going wrong from the
- documentation in chat2.pl, so I thought I would as the net (if nothing
- else, I am guaranteed to get a bunch of people telling me I am not
- much of a perl programmer :-).
-
- The idea behind this is that I can type "addrcheck user@host" and have
- it validate that the user exists on that host (using the SMTP VRFY
- command).
-
- The script is included below. When I run it, it seems to connect to
- the remote sendmail correctly, but always comes back with the message:
- BAD : username: VRFY timeout with hostname ()
- (replace the username and hostname with the ones I gave it on the
- command line).
-
- Can anyone offer any suggestions? I have tested this under perl
- 4.0.1.6 patchlevel 19, and perl 4.0.1.7 patchlevel 35. At this point,
- I am not even sure if the VRFY command is getting to the remote
- sendmail (actually, I am assuming it isn't, but I don't have any way
- of monitoring the port).
-
- Thanks.
-
- 8<------------------------------ Cut Here ------------------------------>8
- #!/usr/local/bin/perl
- #
- # $Id$
- # addrcheck - connect to remote smtp and validate mail address
- #
- # $Log$
- #
-
- require('chat2.pl');
-
- $timeout = 20; # seconds to timeout
- $cr = '\r?\n'; # End of line match
-
- ($n, $a, $port, $servproto) = getservbyname ('smtp', 'tcp');
- if ($port == 0) {
- warn "smtp port not available\n";
- exit;
- }
-
- while (@ARGV) {
- chop;
- $found = "false";
- $addr = shift @ARGV;
- printf " : Validating %s...\n",$addr;
-
- while ($found eq "false") {
- ($user, $host) = split('@', $addr);
-
- printf " : Checking %s at %s...\n",$user,$host;
-
- if (! ($sendmail = &chat'open_port($host, $port)))
- {
- warn "BAD : $user: open failed with $host ($!)\n";
- last;
- }
-
- if (! &chat'expect($sendmail, $timeout, '^220.*$cr', '1'))
- {
- warn "WARN: $user: greeting timeout with $host ($!)\n";
- &chat'close($sendmail);
- last;
- }
-
- &chat'print($sendmail, 'VRFY $user\r\n');
-
- if (! ($result = &chat'expect($sendmail, $timeout,
- '^([0-9][0-9][0-9].*)$cr', '$1')))
- {
- print "BAD : $user: VRFY timeout with $host ($!)\n";
- &chat'close($sendmail);
- last;
- }
-
- chop($result);
- if ($result =~ /^250/) {
- $addr2 = ($result =~ /<(.*)>/);
- ($user2, $host2) = split('@', $addr);
- } else {
- print "BAD : $user: $host: $result\n";
- last;
- }
-
- # If host is null, we have a local address
- if ($host2 eq "") {
- $found = "true";
- print "GOOD: $user: $host: $result\n";
- } else {
- printf "Found %s: %s at %s.\n",$user,$host;
- $addr = $addr2;
- }
- }
- }
- 8<------------------------------ Cut Here ------------------------------>8
-
- --
- Dan Rich | drich@lerc.nasa.gov | (216) 433-4000
- Sr. Systems Engineer | "Danger, you haven't seen the last of me!"
- RMS Technologies, Inc. | "No, but the first of you turns my stomach!"
- NASA Lewis Research Center | -- The Firesign Theatre's Nick Danger
-