Example of Inet6Address in Java

By Arvind Rai, November 14, 2023
Inet6Address is used to create InetAddress instnace by host name or by host address. InetAddress provide canonical name, host address etc. Inet6Address provides IPv6 i.e. Internet protocol version 6 address. Find the sample example.

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
LEARN MORE








©2024 concretepage.com | Privacy Policy | Contact Us