[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Sending commands to a server with MacPerl



At 14.06 97/6/10, bufbill@cloud9.net wrote:
>OK, I found out that the EIMS password server is on port 106, and the
>commands that I have to send to it are
>
>USER username
>PASS password
>NEWPASS newpassword
>QUIT
>
>I am trying to use POP3.pm from the libnet bundle, but it is either
>erroring out, or not changin the password.
>
>Please help me out, and tell me what I have to do in order to
>
>Connect to a server on port 106
>and send the four commands mentioned above.

Try the below.  It is for checking status of a POP account, but could be
easily modified for your purposes.  Note the linebreaks and autoflush.

#!/usr/bin/perl -w
$m      = "\015";       #mac linebreak
$s      = "\015\012";   #socket linebreak
$/      = $s;           #input record is $s

my ($host, $port, $user, $pass) = @ARGV ||
('pop.erols.com','110','cnandor','password');

use IO::Socket;
my $remote = IO::Socket::INET->new(
                        Proto    => "tcp",
                        PeerAddr => $host,
                        PeerPort => $port,
) || die "cannot connect to port $port at $host";

$remote->autoflush(1);

while ( <$remote> ) {
        chomp;print $_,$m;
        if (/\+OK pproxy/)      {&printSock ("USER $user")}
        if (/\+OK Password/)    {&printSock ("PASS $pass")}
        if (/\+OK $user has/)   {&printSock ("QUIT")}
}

#print with $s linebreaks to socket and $m linebreaks to STDOUT
sub printSock {
        my $text = shift;
        print $remote $text,$s;
        print $text,$m;
}

__END__

--
Chris Nandor                 pudge@pobox.com                 http://pudge.net/
%PGPKey=('B76E72AD',[1024,'08 24 09 0B CE 73 CA 10  1F F7 7F 13 81 80 B6 B6'])



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch