KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > net > InetAddress

java.net
Class InetAddress

java.lang.Object
  extended by java.net.InetAddress
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Inet4Address, Inet6Address
See Also:
Top Examples, Source Code, getByAddress(byte[]), getByAddress(java.lang.String, byte[]), getAllByName(java.lang.String), getByName(java.lang.String), getLocalHost()

public boolean equals(Object obj)
See Also:
getAddress()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public byte[] getAddress()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[852]Local Machine IP
By Anonymous on 2004/09/26 13:06:55  Rate
InetAddress iAddr = InetAddress.getLocalHost (  ) ; 
 StringBuffer addrStr = new StringBuffer (  ) ; 
 byte [  ]  bytes = iAddr.getAddress (  ) ; 
 for ( int cnt = 0; cnt  <  bytes.length; cnt++ )  {  
   int uByte = bytes [ cnt ]   <  0 ? bytes [ cnt ]  + 256 : bytes [ cnt ] ; 
   addrStr.append ( uByte ) ; 
   if ( cnt  <  3 )  
     addrStr.append ( '.' ) ; 
  }  
 System.out.println ( "Local Machine IP : "+addrStr.toString (  )  ) ;


public static InetAddress[] getAllByName(String host)
                                  throws UnknownHostException
See Also:
SecurityManager.checkConnect(java.lang.String, int), SecurityException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static InetAddress getByAddress(byte[] addr)
                                throws UnknownHostException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1256]getHostName by IP
By md { dot } sadruddin { at } rediffmail { dot } com on 2005/01/19 08:45:17  Rate
import java.net.*; 
 //import java.net.Inet4Address; 
 class Net 
  {  
   public static void main ( String [  ]  args )  throws Exception 
    {  
     byte [  ]  b=new byte [ 4 ] ; 
     InetAddress ob1=InetAddress.getByName ( "webserv.wipro.com" ) ; 
     b [ 0 ] =new Integer ( 10 ) .byteValue (  ) ; 
     b [ 1 ] =new Integer ( 200 ) .byteValue (  ) ; 
     b [ 2 ] =new Integer ( 81 ) .byteValue (  ) ; 
     b [ 3 ] =new Integer ( 249 ) .byteValue (  ) ; 
     InetAddress ob2=InetAddress.getByAddress ( b ) ; 
     /*System.out.println ( b ) ; 
     System.out.println ( b [ 0 ]  ) ; 
     System.out.println ( b [ 1 ]  ) ; 
     System.out.println ( b [ 2 ]  ) ; 
     System.out.println ( b [ 3 ]  ) ; 
     System.out.println ( ob1 ) ; 
     //Inet4Address ob2=Inet4Address.getByAddress ( b ) ; */
 
     System.out.println ( ob2.getByName ( ob2.getHostName (  )  )  ) ; 
  
  
    }  
  }       


public static InetAddress getByAddress(String host,
                                       byte[] addr)
                                throws UnknownHostException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[750]_
By Anonymous on 2004/08/29 18:48:14  Rate
byte [  ]  b = new byte [ 4 ] ; 
 b [ 0 ]  = new Integer ( 192 ) .byteValue (  ) ; 
 b [ 1 ]  = new Integer ( 168 ) .byteValue (  ) ; 
 b [ 2 ]  = new Integer ( 0 ) .byteValue (  ) ; 
 b [ 3 ]  = new Integer ( 1 ) .byteValue (  ) ; 
        
 // to get the ip address of the server by the name 
 InetAddress ip = InetAddress.getByAddress ( b ) ; 
 


public static InetAddress getByName(String host)
                             throws UnknownHostException
See Also:
SecurityException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getCanonicalHostName()
See Also:
SecurityManager.checkConnect(java.lang.String, int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getHostAddress()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getHostName()
See Also:
SecurityManager.checkConnect(java.lang.String, int), getCanonicalHostName()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[619]Local Host name
By Anonymous on 2004/04/22 02:10:53  Rate
try  {  
       InetAddress addr = InetAddress.getLocalHost (  ) ; 
       String name = addr.getHostName (  ) ; 
       System.out.println ( "Host name = " + name ) ; 
      }  catch  ( UnknownHostException e )   {  
      } 


public static InetAddress getLocalHost()
                                throws UnknownHostException
See Also:
SecurityManager.checkConnect(java.lang.String, int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[618]_
By Anonymous on 2004/01/21 11:37:26  Rate
try  {  
       InetAddress addr = InetAddress.getLocalHost (  ) ; 
       System.out.println ( "Host name = " + addr.getHostName (  )  ) ; 
      }  catch  ( UnknownHostException e )   {  
      } 


public int hashCode()
See Also:
Hashtable, Object.equals(java.lang.Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isAnyLocalAddress()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isLinkLocalAddress()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isLoopbackAddress()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isMCGlobal()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isMCLinkLocal()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isMCNodeLocal()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isMCOrgLocal()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isMCSiteLocal()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isMulticastAddress()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isReachable(int timeout)
                    throws IOException
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isReachable(NetworkInterface netif,
                           int ttl,
                           int timeout)
                    throws IOException
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1887]IsReachable will always return true if network down - here is how to avoid this wrong return
By genefu on 2007/06/06 00:44:10  Rate
boolean test = false; 
                     String local = net.getLocalHost (  ) .getHostAddress (  ) ; 
                     if ( local.compareToIgnoreCase ( "127.0.0.1" ) !=0 )  {  
                     // if network down, localhost set to default loopback ip 
                     // in this case .isReachable (  )  always return true!! -- not what we want 
                         test = net.isReachable ( 1500 ) ; 
                      }  
 


public boolean isSiteLocalAddress()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String toString()
See Also:
Object
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags