To read the sockets, you can use Xniff. It's an API which you can use in your scripts, to read/edit socket information. Search the forums for examples.
Here's one, from Pai:
http://shoutbox.menthix.net/showthread.php?tid=64230
From there, you can probably find the Client ID Steve's talking about
I don't know the Messenger protocol well.. But you can find enough information over at MSNPiki. It's a Wiki about the Messenger protocol.
And yes, it should be possible to do this with a script.
--
vikke