Ports/Services file look up

Simple little script I made to look up port info and possibly Google it all wrapped up in a pretty GUI(using dialogs at least :)).


set f2 to "yes"
repeat while f2 is "yes"
	set x to (display dialog "         Enter port(ddp will cause weirdness)" default answer "80" buttons {"udp", "tcp", "any"} default button {"tcp"})
	set p to text returned of x
	set proto to button returned of x
	if length of p is greater than 5 then
		display dialog "Number to big thats not a port..." buttons {"OK"}
		exit repeat
	end if
	if proto is equal to "any" then
		set lst to "/\" | awk '{print $1}'"
		set setnum to 2
	else
		set lst to "/" & proto & "\" | awk '{print $1}'"
		set setnum to 1
	end if
	set wylf to do shell script "cat /etc/services | grep -i \"" & p & lst
	if number of paragraphs in wylf is greater than setnum then
		log "crap try other form"
		set wylf to do shell script "cat /etc/services | grep -i \" " & p & lst
	end if
	if wylf is equal to "" then
		display dialog "Port not in service file would you like to try searching google?" buttons {"Ok", "Never mind.."}
		if button returned of result is equal to "Ok" then open location "http://www.google.com/search?official_s&q=" & "port+" & p
		exit repeat
	end if
	if number of paragraphs in wylf is equal to 2 then
		set butz to {"Google " & paragraph 1 of wylf & " udp", "Google " & paragraph 2 of wylf & " tcp", "Na I'm good"}
		set dia to "udp:" & paragraph 1 of wylf & "
" & "tcp:" & paragraph 2 of wylf
	else if number of paragraphs in wylf is equal to 3 then
		set butz to {"Google " & paragraph 1 of wylf, "Google " & paragraph 2 of wylf, "Na I'm good"}
		set dia to "ddp:" & paragraph 1 of wylf & "
" & "udp & tcp:" & paragraph 2 of wylf
	else
		set butz to {"Google " & wylf & " " & proto, "Na I'm good"}
		set dia to proto & ": " & wylf
	end if
	display dialog dia buttons butz
	set f to button returned of result
	set finalf to ""
	repeat with i from 2 to number of words in f
		set finalf to finalf & word i of f & "+"
	end repeat
	if f is not "Na I'm good" then open location "http://www.google.com/search?official_s&q=" & finalf
	set f2 to button returned of (display dialog "Wanna check anymore?" buttons {"yes", "no"})
end repeat

There may be easier ways to do some of these things and I might of over coded a couple of parts, if thats the case my bad, I’m pretty new to apple script I haven’t read any tutorial and I just kinda threw this together by Googling stuff and looking at the scripts that come with the system. The weirdness that is caused by ddp is just a different output style. If you have any suggestions post away.