# no shebang line here!!!  This is meant to be run in windows! :)
# see the ActiveState docs for more info





# Obviously you have to be running Kazaa on windows and have user's 
# currently downloading from you for this script to work!!!
use IO::Socket;





# if nothing happens, no info is returned, uncomment this line to
# see your own share info:
#getUser("localhost");exit;





# grab the output from a netstat call into an array:
@netstat=`netstat -an`;





# check each line from the netstat output looking for inbound 
# established connections on port 2541:


foreach $line (@netstat) {
	if($line=~/2541s+(.*?):.*ESTABLISHED/){
		# find out user info for this connection:
		&getUser($1);
	}
}





# subroutine establishes TCP connection to $user IP address on port 1214
# and issues a GET / request:


sub getUser{	
	$user=shift;
	print "IP Address: $user\n";

	# Establish a TCP socket:
	$sock=IO::Socket::INET->new(Proto =>"tcp", PeerAddr=>$user, PeerPort =>"1214",);

	# if we can't connect, issue error - this happens a lot in 
	#kazaa version 2 unfortunately.
	# please fix me! :)
	(print ("cant connect to user $user: $!#######################") && return) unless $sock;





	# if we got here then a socket was established, 
	#send a GET request:


	print $sock "GET / HTTP/1.1";

	# retrieve the data returned:
	while(){
		# NOTE!!!!
		# without this if clause the entire list of files 
		#being shared by the user


		# will be displayed (pre kazaa 2.0 anyway).


		# If you're interested, comment this bit out, 
		#and then run the script on yourself


		# by commenting out the #getUser("localhost")
		#;exit; line above ^^^


		if(/Content-Type:/) {


			last;


		}


		# print out our info:


		print;


	}


	print "#######################";


}
