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('.')
This entry was posted in Groovy and tagged , , , , . Bookmark the permalink.

1 Response to Get the IP address for a host name in Groovy

  1. jobinbasani's avatar jobinbasani says:

    Thanks..this was helpful!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.