SKILL/JAVA

자바 IP관련 클래스 : InetAddress

Jedy_Kim 2017. 12. 19. 21:12
728x90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.net.InetAddress;
 
/*
 * IP 관련 클래스, InetAddress
 * -String getHostAddress()            : 주소 정보를 문자열 반환
 * -String getHostName()            : 컴퓨터 이름 문자열 반환
 * -InetAddress getLocalHost()        : 현재 컴퓨터 InetAddress반환
 * -InetAddress getByName(String hostName) : hostName으로 지정된 컴퓨터 InetAddress 객체 반환
 * -InetAddress[] getAllByName(String hostName) : hostName으로 지정된 모든 컴퓨터 InetAddress 객체 반환
 *                                                     하나의 도메인 이름으로 여러 대의 컴퓨터(서버)를 사용하는 경우
 */
 
public class inetAddressMain {
    public static void main(String[] args) {
        try {
            InetAddress localhost = InetAddress.getLocalHost();
            System.out.println("내 컴퓨터의 이름 : " + localhost.getHostName());
            System.out.println("내 컴퓨터의 주소 : " + localhost.getHostAddress());
            System.out.println("주소 얻어오기");
            InetAddress addr = InetAddress.getByName("www.naver.com");
            System.out.println("InetAddress 객체 반환 : " + addr);
            System.out.println("======================================");
            System.out.println("\t네이버 사용 아이피");
            System.out.println("======================================");
            InetAddress[] addrs = InetAddress.getAllByName("www.naver.com");
            for(InetAddress i : addrs) {
                System.out.println(i);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }        
    }
}
cs


반응형

'SKILL > JAVA' 카테고리의 다른 글

자바 Queue 기본 예제  (0) 2017.12.19
자바 Stack 기본예제  (0) 2017.12.19
자바 Vector연습예제  (0) 2017.12.19
자바 로또 번호 생성 게임예제02  (0) 2017.12.19
자바 로또 번호 생성 게임예제01  (0) 2017.12.19