Hack99.Spy on Skype API Messages


Hack 99. Spy on Skype API Messages

Use these tools to spy on the messages that pass to and fro between Skype and a client that uses its API.

Works with: Windows and Linux versions of Skype.

This hack presents a couple of tools that, if not essential to developing scripts that use the API, are pretty darn useful! Being able to interactively send API commands to Skype and see what Skype sends back in return is invaluable for both developing scripts and debugging them.

12.10.1. Windows

A free tool, Skype Tracer, allows you to interactively send API commands to Skype and see what Skype sends back in return (see Figure 12-6). A nice feature of this tool is that you can save your interactive session to a logfile for later analysis. You can download Skype Tracer at http://share.skype.com/directory/skype_tracer/view/.

12.10.2. Linux

Skype provides an example script, skypeapiclient_linux.py, as part of its API documentation for Linux. Using this script, you can interactively send API commands to Skype and see what Skype sends back in return (see Figure 12-7).

However, Skype's example script has a couple of drawbacks. First, it doesn't give you the option of creating a logfile of your session for later analysis. Although you can cut and paste text from the window and create your own logfile, this is both tedious and error prone. In addition, you can lose text for a long interactive session if the window text buffer has overflowed. Second, it doesn't provide a timestamp, so detailed analysis of exactly when things happened is not possible. To make up for these missing features, I modified the script to provide the missing logfile capability.

Figure 12-6. Skype Tracer allows you to conduct interactive sessions with Skype using its API


Running this new script, which I called skypeapiclient_logging.py, from the command line and piping its terminal output to a filesay, log.txtwill create a logfile of your entire session; for example, like this: python skypeapiclient_logging.py > log.txt.

You can construct the skypeapiclient_logging.py script by copying Skype's skypeapiclient_linux.py script (available as a zip file from http://download.skype.com/share/devzone/example_linux.zip) to skypeapiclient_logging.py and making the changes indicated in bold in the following code listing:

 #!/usr/bin/env python # -*- coding: iso-8859-15 -* # File: skypeapiclient_logging.py 

Figure 12-7. Skype provides an example script that allows you to conduct interactive sessions with Skype using its API


 import dbus, gtk, sys, time class MainWindow:     .     .     . class Callback_obj(dbus.Object):     .     .     . # Skype -> Client messages def Notify(self, message, message_text):     self.mainwindow.write_textbuffer(message_text)     # Skype Hacks: Add these two lines of code      time_stamp = time.strftime("%a, %d %b %Y %H:%M:%S")      print time_stamp + ' MSG RECV FROM SKYPE <-- ' + \            message_text class Api_obj:      .     .     .     # Client -> Skype     def send_message(self, message):         self.mainwindow.write_textbuffer(message)         answer = self.skype_api_object.Invoke(message)         self.mainwindow.write_textbuffer(answer)         # Skype Hacks: Add these three lines of code         time_stamp = time.strftime("%a, %d %b %Y %H:%M:%S")         print time_stamp + ' MSG SENT TO SKYPE --> ' + \               message         print time_stamp + ' MSG RECV FROM SKYPE <-- ' + \               answer         return answer def main():         MainWindow()         gtk.main()      return 0 if __name__ == "__main_ _":         main() 




Skype Hacks
Skype Hacks: Tips & Tools for Cheap, Fun, Innovative Phone Service
ISBN: 0596101899
EAN: 2147483647
Year: 2005
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net