Sunday, September 21, 2008

Find Invisible Users In Gmail

Finding who is invisible is something that I always wanted to do.It's always fun to ping a person who feels none can see him/her online. While studying XMPP protocol I found out that even when the person is offline the chat client knows that person is online.
The Chat Client should know who all are really online at any given time.This is because even when the person is invisible he/she should have a buddy list showing online users.

Ah!! Guess you did'nt understand a word till now.Let me try making it simpler.

Let's assume two users A and B are online now.Both A and B are Available (ie the chat client shows them online).Both A and B has a list of online users in his chat client(eg:google talk,gmail inbox chat,pidgin). Now this online users need to be kept constantly updated. This is done by the XMPP protocol(this is the protocol used by google for it's chat).Now even if B is invisible still it needs to keep it's online users list updated as it needs to show B the online users.
So whenever B logs into his account it initially sends a presence notification to all the users in it's contacts list saying that B is online as "Please show me online in our online user list".
All online users respond back with their online status and status message.
This is where the invisible people shows up.The chat server replies back with their status. The only difference in them is that they respond with their status as "Unavailable".
So my aim was to find out all users that respond back to me with Unavailable status and display them.
Ok enough of explanation of how it works let's see the code

#!/bin/perl

use strict;
use Net::XMPP;

my $sttime=time;
print "Username:$ARGV[0]\n";
my $username = "$ARGV[0]";
my $password = "$ARGV[1]";

my $resource = "SNIFFER";


my $hostname = 'talk.google.com';
my $port = 5222;
my $componentname = 'gmail.com';
my $Contype = 'tcpip';
my $tls = 1;

my %online;
my $Con = new Net::XMPP::Client();
$Con->SetCallBacks(presence=>\&presence_ch);


my $status = $Con->Connect(
hostname => $hostname, port => $port,
componentname => $componentname,
connectiontype => $Contype, tls => $tls);

if (!(defined($status))) {
print "ERROR: XMPP connection failed.\n";
print " ($!)\n";
exit(0);
}



# Change hostname
my $sid = $Con->{SESSION}->{id};
$Con->{STREAM}->{SIDS}->{$sid}->{hostname} = $componentname;

# Authenticate
my @result = $Con->AuthSend(
username => $username, password => $password,
resource => $resource);

if ($result[0] ne "ok") {
print "ERROR: Authorization failed: $result[0] - $result[1]\n";
exit(0);
}
else
{
print "Logged in Sucessfull!\nInvisible Users:\n";
}
$Con->PresenceSend(show=>"Available");
sub presence_ch
{
my $p=0;
my $x;
my $presence = pop;
my $from = $presence->GetFrom();
$from =~ s/([a-zA-Z@.]*)\/(.*)/$1/;
if($presence->GetType() eq "unavailable")
{
if (exists $online{$from})
{
delete($online{$from});
}
else
{
$online{$from}=$presence->GetType()."!!" .$presence->GetStatus();
print $from."\n";
}
}
else
{
$online{$from}=$presence->GetType()."!!" .$presence->GetStatus();
}
}
my $currtime;
while(1)
{
$currtime=time;
if($currtime-$sttime>10)
{last;}
my $res=$Con->Process(1);
if(!(defined($res))){ last;}}



XMPP protocol needs SSL encryption.So you need to install the perl modules for it.So before trying out the code make sure u have the following modules:
  • IO ::Socket ::SSL (>=0.81)
  • XML ::Stream
  • Net ::XMPP
  • Authen ::SASL
To install the packages open the CPAN shell using the command
sudo perl -MCPAN -e 'shell'

Followed by
install <module name>

for each of the module listed above
Also you need to install the package send-xmpp and it's dependecies
sudo apt-get install send-xmpp

Run the program by running it as
perl invi.pl <username> <password>
I have also made a online version of this script you can use to find invisible users the link is
http://sriunplugged.blogspot.com/2008/11/online-version-of-perl-invisible-finder.html
Worked?? Did'nt work?? Comment me

31 comments:

  1. kollaam..nice...good explanation...try cheythu nokaam ....

    ReplyDelete
  2. Hey Srijith

    I tried your code with ActivePerl on Windows and keep getting this error:

    You requested that XML::Stream turn the socket into an SSL socket, but you don't have the correct version of IO::Socket:
    :SSL v0.81. at D:/Perl/site/lib/XML/Stream/Node.pm line 547


    Can you please help resolve this?

    ReplyDelete
  3. you need to use send-xmpp package in linux to avoid that error.
    I am not sure how to install it in windows.But feel there should be a package for it in windows too. Let me see and will get back to you.

    ReplyDelete
  4. Thanks!! Would appreciate if you could let me know.

    ReplyDelete
  5. Good work done...
    Now lets see if i can get more out of it...

    ReplyDelete
  6. Hi Srijith.....I can't able to open this.....while trying to open this site itz coming as HTTP 5000 Internal server error.....can't I view the invisible people anymore.....is this site not working.....

    ReplyDelete
  7. if you tried the online version then it is not working right now. The server I have been using is not allowing communication via post 5222. You can use the program by running the program from your system using the code i posted in this post.

    ReplyDelete
  8. I am using almost the same code to check the invisible users on gtalk & it is working fine for me.

    If I am behind the proxy server of type http, $Contype = 'http'; will work with the same port i.e. 5222;

    if I am directly connecting to internet without any proxy then $Contype must be 'tcpip'

    if I am behind a https proxy server then $Contype = 'http' ; with $port = 443; and the

    connect system call will change to

    #the rest of the parameters u have is same.
    $ssl=1;
    $tls=1;
    Connect(hostname => $hostname,
    port => $port,
    componentname => $componentname,
    connectiontype => $connectiontype,
    tls => $tls,
    ssl => $ssl);

    Check out the blog at

    http://sharathb814.blogspot.com/2009/05/find-invisible-users-in-gmail-gtalk_22.html

    ReplyDelete
  9. I found that server reply status as unavaible if friends are on gmail website but deconnected from the chat. So we can't diff between invisible and deconnected, but we know the guy is reading his emails.

    ReplyDelete
  10. I am getting this error when i tried to run the perl script .. Have installed all the required modules and also have SASL::PLAIN

    No SASL mechanism found
    at C:/Perl/lib/Authen/SASL.pm line 77
    at C:/Perl/lib/XML/Stream.pm line 2123

    Can you help me?

    ReplyDelete
  11. Check if that file is present in that folder. If not it's a path issue.Find where the module is installed and point to that file in the configuration of perl

    ReplyDelete
  12. got an error XMPP connection failed.

    ReplyDelete
  13. can u tell me hoe i install this script
    i dont hve any idea how to install this

    ReplyDelete
  14. can u tell me how to install this script
    i dont hve any idea how to install this..do plzz hlp me...thnk q

    ReplyDelete
  15. I am using cygwin and getting following error:

    Can't locate Net/XMPP.pm in @INC (@INC contains: /usr/lib/perl5/5.10/i686-cygwin /usr/lib/perl5/5.10 /usr/lib/perl5/site_perl/5.10/i686-cygwin /usr/lib/perl5/site_perl/5.10 /usr/lib/perl5/vendor_perl/
    5.10/i686-cygwin /usr/lib/perl5/vendor_perl/5.10 /usr/lib/perl5/vendor_perl/5.10 /usr/lib/perl5/site_perl/5.8 /usr/lib/perl5/vendor_perl/5.8 .) at invi.pl line 4.
    BEGIN failed--compilation aborted at invi.pl line 4.

    Can you please help ?

    ReplyDelete
  16. http://www.ormakal.net/cgi-bin/invi.pl

    forbidden....

    not working

    ReplyDelete
  17. good job...
    it works..

    thanks :)

    ReplyDelete
  18. I want to try this out. But I am not a pearl programmer. Tell me what development kit/shell or whatever I need to install to run this script. please provide the link to the software store as well.

    ReplyDelete
  19. Great one !!!!;;;;

    ReplyDelete
  20. Great buddy ....It works....The very first time i installed strawberry perl and ran ur script with ur steps..Its working fine.....Great dude...

    ReplyDelete
  21. grt..its working fine...

    ReplyDelete
  22. Hi Frnd,Nice work.....
    I m trying ur Script in WindowsXP....So i installed Perl (from here www.gossland.com/cours/install_perl.html).......
    Im getting Error
    "Can't locate Net/XMPP.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at gtak.pl line 4.
    BEGIN failed--compilation aborted at gtak.pl line 4."
    Can u plzzzzz solve this prob???? ....reply plz..byee

    ReplyDelete
  23. how to run the script in windows?

    ReplyDelete
  24. http://www.ormakal.net/cgi-bin/invi.pl this isn't works brother...can u suggests me a way 2 do dis pls? i wnna see ma invisible buddies??

    ReplyDelete
  25. pls tel me how 2 run dis and where 2 run dis source code??? i am struggling friends...

    ReplyDelete
  26. I am struggling to understand it...


    please mail me at mathematics248@gmail.com

    ReplyDelete
  27. make one zip files program man..so it will be easy for all..keep it simple....and well done...

    ReplyDelete
  28. dude can u do perl to exe plz?
    Tried things on windows wasnt able to achieve

    ReplyDelete
  29. Hello Boss....gr8 job...loved it and was using it for long time now. But from last 3 days script is acting up, it does not show any invisible user at all. I am using it with my local machine. I tried to modify script a bit (invert the logic) and found that it is able to return Available users but does not work for invisible. Has something changed ??

    ReplyDelete
  30. The newer version of this code is at - http://blog.sriunplugged.com/linux/find-invisible-users-in-gmail/
    Try it and tell if it works

    ReplyDelete