Whois and Ping

I just felt like it.

property default : "macscripter.net"

set button to button returned of (display dialog "What do you want to do?" buttons {"Ping", "Whois"} default button {"Whois"})
if button is "Ping" then
	set numb to (choose from list {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} with prompt "How many packets do you want sent?") as integer
	set s to "s"
	if numb is 1 then set s to ""
	ping(numb, text returned of (display dialog "What site do you want to ping " & numb & " time" & s & "?" default answer default buttons {"Whois"} default button 1))
else
	whois(text returned of (display dialog "What site do you want to whois?" default answer default buttons {"Whois"} default button 1))
end if
on ping(numb, thesite)
	display dialog "This might take time. Continue?" buttons {"Cancel", "OK"} cancel button {"Cancel"} default button {"OK"}
	try
		set ping to do shell script "ping -c " & numb & space & quoted form of thesite
		set siteping to paragraphs of ping
		choose from list siteping with prompt "" OK button name "Finish" cancel button name "Finish"
	on error e
		display dialog "An error has occured:" & return & return & return & e
	end try
end ping
on whois(thesite)
	try
		set whois to do shell script "whois " & quoted form of thesite
		set sitewhois to paragraphs of whois
		choose from list sitewhois with prompt "" OK button name "Finish" cancel button name "Finish"
	on error e
		display dialog "An error has occured:" & return & return & return & e
	end try
end whois

Along the same lines, some years ago now Kai Edwards posted this script for finding numerical IP Addresses from URLs. What’s amazing to me is that IP Addresses exist for many of your wildest guesses.

text returned of (display dialog "Enter a URL in the text box below:" default answer ¬
	"[url=http://www.apple.com]www.apple.com[/url]" buttons {"OK"} default button 1) as string returning {text:theURL}
-- the following line presumes that a reasonable URL has been entered in the form given by the default - it will not correct anything else.
if theURL does not contain "http://" then set theURL to "http://" & theURL
try
	set theHost to (dotted decimal form of ((theURL as URL))'s host)
	display dialog (theURL & "'s IP Address is: " & theHost) buttons {"OK"} default button 1
on error
	display dialog "No such URL" buttons {"Too Bad"} default button 1
end try

Yeah, I discovered the “as URL” a long time ago and messed with it. Isn’t that helpful?

P.S.
Shouldn’t

if theURL does not contain "http://" then

be

if theURL does not start with "http://" then