-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInetAddressExample.java
More file actions
25 lines (22 loc) ยท 950 Bytes
/
InetAddressExample.java
File metadata and controls
25 lines (22 loc) ยท 950 Bytes
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
package ch19.sec02;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class InetAddressExample {
public static void main(String[] args) {
try {
InetAddress local = InetAddress.getLocalHost();
System.out.println("๋ด ์ปดํจํฐ IP ์ฃผ์: " + local.getHostAddress());
/*
* getByName() : ๋๋ฉ์ธ ์ด๋ฆ์ผ๋ก ๋ฑ๋ก๋ ๋จ ํ๋์ IP ์ฃผ์
* getAllByName() : ๋ฑ๋ก๋ ๋ชจ๋ IP ์ฃผ์๋ฅผ ๋ฐฐ์ด๋ก
* getHostAddress() : InetAddress ๊ฐ์ฒด์์ IP ์ฃผ์๋ฅผ ์ป๊ธฐ ์ํด ์ฌ์ฉํ๋ ๋ฉ์๋
*/
InetAddress[] iaArr = InetAddress.getAllByName("www.naver.com");
for (InetAddress remote : iaArr) {
System.out.println("www.naver.com IP ์ฃผ์: " + remote.getHostAddress());
}
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}