JAVA/CONCEPT
JAVA chapter18. IO 기반 입출력 및 네트워킹. 18.6 네트워크 기초
너래쟁이
2018. 1. 17. 18:27
JAVA chapter18. IO 기반 입출력 및 네트워킹.
18.6 네트워크 기초
18.6.1 서버와 클라이언트
18.6.2 IP 주소와 포트(Port)
18.6.3 InetAddress로 IP 주소 얻기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | package sec06.exam01_inetaddress; 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()); 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(); } } } | cs |