Get the IP address for a host name in Groovy

I was playing around with some Groovy scripts and looking at some neat tip and tricks on how Groovy can simplify what would have taken a lot more code in Java. Here is one that came up with: print out the IP address in dot notation of a given host.

def hostname = 'google.com'
println InetAddress.getByName(hostname).address.collect { it & 0xFF }.join('.')
Posted in Groovy | Tagged , , , , | 1 Comment