JAVA NETWORKING INETADDRESS METHODS
InetAddress methods:
![]() |
NETWORKING INETADDRESS METHODS |
The InetAddress class from java.net
package represents an Internet Protocol
(IP) address.
The java.net.InetAddress class provides methods
to get an IP of host name.
It is the superclass of Inet6Address and Inet4Address classes.
There are no constructors for this class
but static methods
which returns instances of InetAddress class for general use.
We will now discuss the three
important methods from InetAddress class.
1.getLocalHost
2.getByName
3.getAllbyName
JAVA PROGRAM:
Import java.net.*;
Import java.*;
Class InetAddress
{
Public static void main(String [] args) throws unknown
Host Exception
{
If(address.isLoopbackAddress())
System.out.println(“it’s a loop back address”+address);
Else
System.out.println(“its not a loop back address”+address);
}
}
METHODS FOR TYPES OF IP ADDERSSES:
1.isLoopbackAddress()
This method is a Boolean method which returns true if
the address given to it is a loop back address(i.e.100.0.0.1).
2.isAnyLocalAddress()
This is a Boolean method which returns true if the
system has a local ip address.
3.isSiteLocalAddress()
This method returns true if the address is ipv6 site
local address.
4.isMulticasAddress()
This method returns true if the address is a multicast
address otherwise it returns false.
5.isMCGlobal()
This method returns true if the address is a multicast
address with global scope, other wise it returns false.
6.isMCNodeLocal()
This method returns true if the address is a multicast
address with node-local scope, other wise it returns false.
Post a Comment