'whois' AppleScript for Safari in: AppleScript
Run this from your AppleScript menuextra if you want a 'whois' on the domain of the current page in Safari.

This may seem fairly useless, but I thought of doing it this way while shopping online through PriceGrabber.com. One of the hits returned there was at a site that just didn't look right. Even the domain was broken english. I ran 'whois' on it and thought, "Why not AppleScript it?" So, here that is.


property whoisOptions : "" -- Include a 'space' after EVERY option. -- List of second level country code domains. Not all inclusive hence not very reliable. property coTLDs : {"co", "com", "ne", "net", "or", "org"} property theFile : (((path to temporary items) as text) & "who_it_is.txt") tell application "Safari" set pageURL to URL of document 1 as string set theName to my hostFind(pageURL) my makeTXT(theName, pageURL) open theFile end tell on makeTXT(theName, pageURL) try set TXTcode to "(whois info for - " & pageURL & ")" & return & ¬ (do shell script "whois " & whoisOptions & theName) on error err set TXTcode to "Oops!" & return & return & err end try tell application "Finder" set newFile to (open for access theFile with write permission) set eof newFile to 0 write TXTcode to newFile close access newFile end tell end makeTXT on hostFind(theURL) set old_delims to AppleScript's text item delimiters set AppleScript's text item delimiters to "/" set theURL to item 3 of (text items of theURL) -- log theURL set AppleScript's text item delimiters to "." if (last character of last word of theURL) is in {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} then set theHost to theURL else set nameList to every text item of theURL set wordCount to (count of nameList) as integer set theTLD to item wordCount of nameList if (count of characters of theTLD) < 3 then if (item (wordCount - 1) of nameList) is in coTLDs then set theDomain to item (wordCount - 2) of nameList & "." & item (wordCount - 1) of nameList else set theDomain to item (wordCount - 1) of nameList end if else set theDomain to item (wordCount - 1) of nameList end if set theHost to theDomain & "." & theTLD end if set AppleScript's text item delimiters to old_delims return theHost end hostFind



Update: Now uses plain text as output and can handle IP addresses. Really useful if you browse server logs using Safari.

Update: Will find domains with an international TLD (e.g., google.co.uk).
Edit: December 25, 2007, 11:14 pm