[] STUDY ³»¿ë

ÀÛ¼ºÀÏ 2003-10-22
ÀÛ¼ºÀÚ park
Á¶È¸¼ö 1790
Á¦ ¸ñ InetAddress¸¦ »ç¿ëÇÏ¿© IPÁÖ¼Ò ¾Ë¾Æ³»±â

¸ñ·ÏÀ¸·Î | ¼öÁ¤ | »èÁ¦ | Á¤º¸Ãß°¡[reply] | ½Å±ÔÀÔ·Â

InetAddess  Å¬·¡½º¸¦  »ç¿ëÇÏ¿©  ·ÎÄà È£½ºÆ®¸í°ú  IPÁÖ¼Ò,  Æ¯Á¤  µµ¸ÞÀÎÀÇ  IPÁÖ¼Ò¸¦  ¾Ë¾Æ³»  º¸ÀÚ.

¸ÕÀú  InetAddress  Å¬·¡½º  »Ó¸¸  ¾Æ´Ï¶ó  ³×Æ®¿öÅ©¿¡  °ü·ÃµÈ  Å¬·¡½º¸¦  »ç¿ëÇÏ·Á¸é  java.net  ÆÐÅ°Áö¸¦  import  ½ÃÄѾߠ µÈ´Ù.

import  java.net.*;

ÀÚ¹Ù¿¡¼­´Â  À§ÀÇ  ÇÑÁٷΠ °ÅÀÇ  ¸ðµç  ³×Å©¿öÅ©  ¸ðµâÀ»  ¸¸µé  ¼ö  ÀÖ´Ù.  Á¤¸»  ½Å³ªÁö  ¾ÊÀ»  ¼ö  ¾ø´Ù.  InetAddress  Å¬·¡½º´Â  º°µµÀÇ  »ý¼ºÀÚ°¡  Á¸ÀçÇÏÁö  ¾Ê´Â´Ù.  µû¶ó¼­  getByName()À̳ª  getLocalHost()¸Þ¼Òµå¸¦  »ç¿ëÇÏ¿©  InetAddress¿¡  ´ëÇÑ  °´Ã¼¸¦  »ý¼ºÇÏ°í,  ¿øÇϴ  È£½ºÆ®ÀÇ  ³×Æ®¿öÅ©  °ü·Ã  Á¤º¸¸¦  °¡Á®¿Â´Ù.

InetAddress  address  =  InetAddress.getByName(hostName);  //  or
InetAddress  address  =  InetAddress.getLocalHost();

À§¿¡¼­  hostNameÀº  string  ÇüÅÂÀÇ  ¹®ÀÚ¿­À̸頠µÈ´Ù.  ±×·Á¸é  ÇØ´ç  µµ¸ÞÀÎÀ̳ª  IPÀÇ  ³×Æ®¿öÅ©  °ü·Ã  Á¤º¸¸¦  °¡Á®¿Ã  ¼ö  ÀÖ´Ù.

»ý¼ºµÈ  °´Ã¼  addressÀ»  »ç¿ëÇÏ¿©  getHostName()°ú  getHostAddress()¸Þ¼Òµå¸¦  »ç¿ëÇÏ¿©  È£½º¸í°ú  È£½ºÆ®ÀÇ  IPÁÖ¼Ò¸¦  °¡Á®¿ÀÀÚ.

InetAddress  address1  =  InetAddress.getByName(hostName);
System.out.println("Host  Name="  +  address1.getHostName());
System.out.println("Host  Address  =  "  +  address1.getHostAddress());


InetAddress  address2  =  InetAddress.getLocalHost();
System.out.println("Local  Name  =  "  +  address2.getHostName());
System.out.println("Local  Address  =  "  +  address2.getHostAddress());

¸¶Áö¸·À¸·Î  InetAddress¿Í  °°ÀÌ  ³×Å©¿öÅ©¿¡  °üÇÑ  Å¬·¡½º¸¦  »ý¼ºÇÏ·Á¸é  ¿¹¿Ü󸮸¦  ¹Ýµå½Ã  ÇØÁÖ¾î¾ß  ÇÑ´Ù.  µû¶ó¼­  main()ÇÔ¼ö¿¡  ¿¹¿Ü󸮸¦  ÇØ  Áֱ⠠À§ÇØ  throws¸¦  »ç¿ëÇÏ¿´´Ù.

public  static  void  main(String  args[])  throws  Exception

À§¿¡¼­  ¼³¸íµÈ  ¸ðµç  ºÎºÐÀÇ  ¼Ò½º´Â  ¾Æ·¡¿Í  °°´Ù.

import  java.net.*;

public  class    InetAddressEx2
{
    public  static  void  main(String  args[])  throws  Exception
    {
        String  hostName="yahoo.com";
        InetAddress  address1  =  InetAddress.getByName(hostName);
        System.out.println("Host  Name="  +  address1.getHostName());
        System.out.println("Host  Address  =  "  +  address1.getHostAddress());


        InetAddress  address2  =  InetAddress.getLocalHost();
        System.out.println("Local  Name  =  "  +  address2.getHostName());
        System.out.println("Local  Address  =  "  +  address2.getHostAddress());
    }            
}

InetAddress¸¦ »ç¿ëÇÏ¿© IPÁÖ¼Ò ¾Ë¾Æ³»±â °ú(¿Í) °ü·ÃµÈ Ãß°¡ Á¤º¸

  • URL Ŭ·¡½º [2003-10-23] [park´Ô Àç°ø] [Á¶È¸:729]
  • InetAddress¸¦ »ç¿ëÇÏ¿© IPÁÖ¼Ò ¾Ë¾Æ³»±â [2003-10-22] [park´Ô Àç°ø] [Á¶È¸:1790]

    ¸ñ·ÏÀ¸·Î | ¼öÁ¤ | »èÁ¦ | Á¤º¸Ãß°¡[reply] | ½Å±ÔÀÔ·Â