It was initially possible to gain the IP of the person you are chatting with in Yahoo Chat / Yahoo messenger using the netstat command or a simple GUI tool like Process Explorer. for Windows. However, Yahoo fixed that. Still, if you try to use a ‘packet sniffer’ program you should be able to do that.
You can try ethereal or winpcap [http://www.ethereal.com (for ethereal) ; http://winpcap.polito.it/ (for winpcap)]. However, network sniffing may be illegal in your area and you should check beforehand. Then you need to get a whois program.
You can get one here: http://www.snapfiles.com/get/trout.html