Catch Invisible Friends On GTalk The Python Way
July 16th, 2010
Ever wanted to know that someone is really offline or has just gone invisible in GTalk? Here is a small trick. The bellow peace of python code get the list of invisible users from your GTalk buddy list. It uses XMPP module for python. You can install this module in Ubuntu/Debian via apt. It also requires python dns module.
$ sudo aptitude install python-xmpp python-dnspython
Now here is our script. Open your favorite text editor and save the code as ‘gchat.py’. Dont forget to fill your gtalk username and password in the script.
import xmpp # Google Talk constants FROM_GMAIL_ID = "username@gmail.com" GMAIL_PASS = "secret" GTALK_SERVER = "gmail.com" jid=xmpp.protocol.JID(FROM_GMAIL_ID) C=xmpp.Client(jid.getDomain(),debug=[]) if not C.connect((GTALK_SERVER,5222)): raise IOError('Can not connect to server.') if not C.auth(jid.getNode(),GMAIL_PASS): raise IOError('Can not auth with server.') C.sendInitPresence(requestRoster=1) def myPresenceHandler(con, event): if event.getType() == 'unavailable': print event.getFrom().getStripped() C.RegisterHandler('presence', myPresenceHandler) while C.Process(1): pass
Now simply run:
$ python gchat.py
So , Next time do not let anyone fool you , rather catch him Invisibly .
Related posts:
Nice trick. I’ll give it a try. Cheers !
Hi, im getting this error when running the script:
$ python gchat.py
File “gchat.py”, line 24
raise IOError(‘Can not connect to server.’)
^
IndentationError: expected an indented block
I’ve made the file executable, and also tried to run it as root. Can you give some help ? Thanks
Hi… me again. Seems like i copied/pasted it and gave a bad format to the text. Now the script runs, … BUT this is what i get:
$ python gchat.py
/usr/lib/python2.6/dist-packages/xmpp/auth.py:24: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
import sha,base64,random,dispatcher,re
/usr/lib/python2.6/dist-packages/xmpp/auth.py:26: DeprecationWarning: the md5 module is deprecated; use hashlib instead
import md5
/usr/lib/python2.6/dist-packages/xmpp/transports.py:308: DeprecationWarning: socket.ssl() is deprecated. Use ssl.wrap_socket() instead.
tcpsock._sslObj = socket.ssl(tcpsock._sock, None, None)
And stands there, and does nothing for as long i let it.
If i do CTRL+C to abort the execution:
Traceback (most recent call last):
File “gchat.py”, line 23, in
while C.Process(1):
File “/usr/lib/python2.6/dist-packages/xmpp/dispatcher.py”, line 119, in Process
if self._owner.Connection.pending_data(timeout):
File “/usr/lib/python2.6/dist-packages/xmpp/transports.py”, line 302, in pending_data
return self._tcpsock._seen_data or select.select([self._tcpsock._sock],[],[],timeout)[0]
KeyboardInterrupt
The same happens if i run it as root. Am i missing something ?
Thank you for your help.
I used this code snippet earlier and it worked. But now it doesn’t seem to work in any python versions.