I’ve recently used a site that allows querying WHOIS servers and got annoyed by the requirement of every time typing in the captcha key, so I thought to myself: “Wouldn’t it be groovy to write a Groovy WHOIS client?”. Well, it is :) So without any further ado, I’m presenting that finished script to you.
def domain = args.length > 0
? args[0] : 'google.com'
def server = args.length > 1
? args[1] : 'whois.geektools.com'
new Socket(server, 43).withStreams {input, output ->
output << "${domain}\r\n"
println input.text
}
As you can see, the script uses Groovy extensions to JDK classes, such as Socket (method withStreams(Closure)), InputStream (getText()) and OutputStream(leftShift(Object)). Neat, huh?
Keep on coding!
Psyho
Posted in groovy at September 10th, 2008. by Adam 'Psyho' Pohorecki 2 Comments.