Multiple results in one dialogue

Hi,
I’m using a script to tell me the names of other people on our network who are connected to my machine. We’ve got the fundamentals down, but it’ll only return one user by matching the IP address to a name:

do shell script “netstat -W | grep -E ‘EST|Foreign’”
set theResult to result as text
if theResult contains “afpovertcp 192.168.1.20” then
display dialog “Joe Blogs is still connected to you”
end if

How can I make this identify a series of IP addresses, and a list of appropriate names in the dialogue?

Thanks

Untested at the moment, but should work.

-- The connections you are going to look for
set knownConnections to {¬
	{"afpovertcp  192.168.1.20", "Joe Blogs"}, ¬
	{"afpovertcp  192.168.1.22", "John Doe"}, ¬
	{"afpovertcp  192.168.1.23", "Susan Summers"}, ¬
	{"afpovertcp  192.168.1.200", "The one called I am"}}

set currentConnections to do shell script "netstat -W | grep -E 'EST|Foreign'"

repeat with aConnectionEntry in knownConnections
	if currentConnections contains item 1 of aConnectionEntry then display dialog item 2 of aConnectionEntry & " is still connected to you"
end repeat

Thanks for that … doesn’t seem to work though. It runs, but nothing happens.

Odd, well as soon as I get into work this morning I will test out and see what stupid little mistake I made :smiley:

I was doing my own but James beat me to it.
this just cleans up the display
**edit , I can not test this against the type of results you may get as I do not have the sort of network connections needed.
In my results I do not get afpovertcp in my results so I just used the IP address in the item 1 field

-- The connections you are going to look for
set knownConnections to {¬
   {"afpovertcp 192.168.1.20", "Joe Blogs"}, ¬
   {"afpovertcp 192.168.1.22", "John Doe"}, ¬
   {"afpovertcp 192.168.1.23", "Susan Summers"}, ¬
   {"afpovertcp 192.168.1.200", "The one called I am"}}

set currentConnections to do shell script "netstat -W | grep -E 'EST|Foreign'"
set Connected_list to ""
repeat with aConnectionEntry in knownConnections
	if currentConnections contains item 1 of aConnectionEntry then
		set Connected_list to Connected_list & "* " & item 2 of aConnectionEntry & return
	end if
end repeat
if Connected_list is not "" then
	display dialog Connected_list & return & "still connected to you"
end if

Sam,

I ran the code I posted and it worked fine without any modifications so I’m not sure what the problem might be.

Can you run the netstat comamnd and post the output here? Underline or bold the connections you are trying to find?

All works fine now! afpovertcp was unneeded, it turned out. Thanks very much guys.
One slight oddity “ I also use a script to quickly connect to specific computers on our network. If I’M connected to someone through this script, it returns that persons name as connected to ME. If I connect through double clicking the network icon in the finder window, there’s no problem.
Any explanations?