네트워크
ip, url, tcp
InetAddress : ip 정보와 연관된 클래스 (ip 정보 관리)
소스
public static void main(String[] args) {
try {
// 현재 컴퓨터의 IP 주소 얻기
InetAddress local = InetAddress.getLocalHost();
System.out.println(local);
System.out.println(local.getHostName());
System.out.println(local.getHostAddress());
// 외부 사이트의 IP 주소 얻기
//InetAddress jun = InetAddress.getByName("www.9999.com");
InetAddress jun = InetAddress.getByName("www.jun2food.com");
System.out.println(jun);
// 대형사이트의 IP 주소 모두 얻기
InetAddress[] navers = InetAddress.getAllByName("www.naver.com");
for(InetAddress naver : navers) {
System.out.println(naver);
}
} catch (Exception e) {
e.printStackTrace();
}
}
결과
PC/xxx.xxx.xxx.xxx // 내PC/내IP
PC // 내 PC 이름
xxx.xxx.xxx.xxx // 내 PC IP
www.jun2food.com/203.246.167.175
www.naver.com/125.209.222.142
www.naver.com/210.89.164.90
Java - 연결된 url로부터 데이터 읽기 (0) | 2018.10.02 |
---|---|
Java - URL 정보 확인, URLConnection (0) | 2018.10.02 |
Java - IO, finnaly문 정리 (0) | 2018.10.02 |
Java - IO, PrintWriter 사용 (0) | 2018.10.02 |
Java - IO, File 클래스를 이용한 파일 복사 (0) | 2018.10.02 |
댓글 영역