Home  >  Core Java

Example of Inet6Address in Java

By Arvind Rai, April 06, 2013
Inet6Address is used to get InetAddress by host name or by host address. InetAddress can provide canonical name, host address etc. Inet6Address provides IPv6 i.e. Internet protocol version 6 address. Find the sample example.
Inet6AddressTest.java
package com.concretepage;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class Inet6AddressTest {
    public static void main(String[] args) throws UnknownHostException {
        String host = "facebook.com";
        InetAddress[] inAdd = Inet6Address.getAllByName(host);
        for(InetAddress ia:inAdd){
            System.out.println(ia.getCanonicalHostName());
            System.out.println(ia.getCanonicalHostName());
        }
        InetAddress ina=Inet6Address.getLocalHost();
        System.out.println(ina.getCanonicalHostName());
        System.out.println(ina.getHostAddress());
    }
}
Output
edge-star-mini-shv-17-prn1.facebook.com
edge-star-mini-shv-17-prn1.facebook.com
192.168.8.100
192.168.8.100
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us