Tutorial / Howto / How-to...
perl script to send jabber message to Google Talk / Googletalk Instant Messaging using XMPP protocol and SASL PLAIN authentication. Check that these perl modules are installed :
- IO ::Socket ::SSL (>=0.81 ?)
- XML ::Stream
- Net ::XMPP
- Authen ::SASL
#!/usr/bin/perl -w
#
# script to send jabber message to Google Talk Instant Messaging
# using XMPP protocol and SASL PLAIN authentication.
#
# author: Thus0 <Thus0@free.fr>
# Copyright (c) 2005, Thus0 <thus0@free.fr>. All rights reserved.
#
# released under the terms of the GNU General Public License v2
use strict;
use Net::XMPP;
## Configuration
my $username = "thus0";
my $password = "XXXXX";
my $to = "petrus";
my $body = "hello world";
my $resource = "PerlBot";
## End of configuration
#------------------------------------
# Google Talk & Jabber parameters :
my $hostname = 'talk.google.com';
my $port = 5222;
my $componentname = 'gmail.com';
my $connectiontype = 'tcpip';
my $tls = 1;
#------------------------------------
my $Connection = new Net::XMPP::Client();
# Connect to talk.google.com
my $status = $Connection->Connect(
hostname => $hostname, port => $port,
componentname => $componentname,
connectiontype => $connectiontype, tls => $tls);
if (!(defined($status))) {
print "ERROR: XMPP connection failed.\n";
print " ($!)\n";
exit(0);
}
# Change hostname
my $sid = $Connection->{SESSION}->{id};
$Connection->{STREAM}->{SIDS}->{$sid}->{hostname} = $componentname;
# Authenticate
my @result = $Connection->AuthSend(
username => $username, password => $password,
resource => $resource);
if ($result[0] ne "ok") {
print "ERROR: Authorization failed: $result[0] - $result[1]\n";
exit(0);
}
# Send message
$Connection->MessageSend(
to => "$to\@$componentname", body => $body,
resource => $resource);
Commentaires
1. dimanche 9 avril 2006 à 18:04, par Etienne
2. vendredi 2 juin 2006 à 14:09,
3. vendredi 6 juillet 2007 à 02:29,
4. dimanche 8 juillet 2007 à 14:12, :: digitalpbk
5. mardi 5 février 2008 à 13:48, par JJ :: Ne marche pas
6. mercredi 6 février 2008 à 09:45, par Thus0
7. mercredi 18 juin 2008 à 11:12, par Amol
Ajouter un commentaire