DNS is an internet service that maps domain names, like rosettacode.org, to IP addresses, like 66.220.0.231.

Use DNS to resolve www.kame.net to both IPv4 and IPv6 addresses. Print these addresses.




// version 1.1.3
 
import java.net.InetAddress
import java.net.Inet4Address
import java.net.Inet6Address
 
fun showIPAddresses(host: String) {
    try {
        val ipas = InetAddress.getAllByName(host)
        println("The IP address(es) for '$host' is/are:\n")
        for (ipa in ipas) {
            print(when (ipa) {
                is Inet4Address -> "  ipv4 : "
                is Inet6Address -> "  ipv6 : "
                else            -> "  ipv? : "
            })
            println(ipa.hostAddress)
        }
    }
    catch (ex: Exception) {
        println(ex.message)
    } 
}
 
fun main(args: Array<String>) {
    showIPAddresses("www.kame.net")
}