Google Talk with perl (bis)
Par Thus0, vendredi 9 décembre 2005 à 09:19 :: perl ::#79
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
Bonjour,
très intéressé par ce petit prog. je m’empresse de le tester et ...
Use of uninitialized value in concatenation (.) or string at /usr/share/perl5/XML/Stream.pm line 1610. Use of uninitialized value in string eq at /usr/share/perl5/XML/Stream.pm line 1613. Use of uninitialized value in string ne at hobbit2gtalk.pl line 71. Use of uninitialized value in concatenation (.) or string at hobbit2gtalk.pl line 72. Use of uninitialized value in concatenation (.) or string at hobbit2gtalk.pl line 72. ERROR : Authorization failed : -
Je n’arrive pas a voir pourquoi...
Etienne
This does not work. I keep getting msg :
"ERROR : Authorization failed : - "
I am using the correct username/password. have double checked them in GTalk client, and they work ok.
What is wrong ?
works great for me, thanks !
hiii
I get this
Cannot resolve localhost.localdomain : at /usr/lib/perl5/site_perl/5.8.8/XML/Stream.pm line 406.
any solutions ?
I couldn’t make this work. XML ::Stream has an old bug, that prevents it from working within intranets with machines indirectly connected to the Internet
you mean use XML ::Stream through proxy ?
Do you have more informations about that bug ?
Thanks friend...that works just great.....
Note : port 80 works juat as well. Useful if you’re behind some sort of firewall.