PDA

View Full Version : iTunes and LAN sharing - any way to find out who is connected?


toonnation
07-23-2003, 09:29 PM
and what they are listening to?

is this scriptable? or would you need a plugin?

cheers
Andy

deeg
07-24-2003, 08:04 AM
this is something i was playing with while net sharing was possible, it does show either the i.p address or if possible the results of an nslookup for any connected ip address.. the kill option does not work currently.. have yet to find a method to do that...it splits those who are connected into those who are either just browsing your library and those who are actively listening


-- initialise the required lists for later use
set Listeners to {}
set Browsers to {}

-- find out whats required....
display dialog "What would you like to know?" buttons {"Show Listeners", "Show Browsers"}
set UserChoice to button returned of the result

(* shell to find active connections to port 3689 .. selecting sendq and foreign address info only
returned as text file so split into list*)

set x to (do shell script "netstat -f inet -W -n | awk '$4 ~ /3689/ {print $3,$5}'")
try
set old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {return}
set ActiveSessions to text items of x as list
set AppleScript's text item delimiters to old_delims
end try

-- reset tid to get just the ip address as required
set AppleScript's text item delimiters to " "

-- loop with each session and if send-q is 33304 then they are listening else just browsing
repeat with aSession in ActiveSessions
if aSession contains "33304" then copy (text item 2 of aSession) to end of Listeners
if aSession does not contain "33304" then copy (text item 2 of aSession) to end of Browsers
end repeat

-- proccess listeners and browser lists to see if we can get a url
set Listeners to my FindURL(Listeners)
set Browsers to my FindURL(Browsers)

-- return delims to old value
set AppleScript's text item delimiters to old_delims

-- show the results as desired
if UserChoice is "Show listeners" then
if Listeners is {} then
display dialog "No active Listeners found"
else
choose from list Listeners with prompt "The Following Listeners Found:" OK button name "kill session" with multiple selections allowed
end if
end if
if UserChoice is "Show Browsers" then
if Browsers is {} then
display dialog "No active Browsers found"
else
choose from list Browsers with prompt "The Following Browsers Found:" OK button name "kill session" with multiple selections allowed
end if
end if
set old_delims to AppleScript's text item delimiters

-- subroutine for nslookups
on FindURL(the_list)
set AppleScript's text item delimiters to "."
set inter_list to {} -- holding list of urls/ip's found
repeat with aSession in the_list
set aSession to (text items 1 through 4 of aSession) as string
set x to "nslookup " & aSession & " 2>&1 | awk '/Name/ {print $2} /Non-existent/ {print $5} '"
set theURL to (do shell script x)
if theURL contains ":" then
copy aSession to end of inter_list
else
copy theURL to end of inter_list
end if
end repeat
return (inter_list)
end FindURL


there is a method of looking at what is being accessed in your music repository (lsof command i think) but i found it unreliable.

toonnation
07-24-2003, 12:51 PM
thanks....!