Inet4Address in Java
November 14, 2023
Inet4Address
is instantiated by host name or by host address. InetAddress
provides canonical name, host address etc. Inet4Address
is IPv4 i.e. Internet protocol version 4 address. Find the sample example.
Example
Inet4AddressTest.javapackage com.concretepage; import java.net.Inet4Address; import java.net.InetAddress; import java.net.UnknownHostException; public class Inet4AddressTest { public static void main(String[] args) throws UnknownHostException { String host = "facebook.com"; InetAddress[] inAdd = Inet4Address.getAllByName(host); for(InetAddress ia:inAdd){ System.out.println(ia.getCanonicalHostName()); System.out.println(ia.getCanonicalHostName()); } InetAddress ina=Inet4Address.getLocalHost(); System.out.println(ina.getCanonicalHostName()); System.out.println(ina.getHostAddress()); } }
edge-star-mini-shv-17-prn1.facebook.com edge-star-mini-shv-17-prn1.facebook.com 192.168.8.100 192.168.8.100