Java

[Java] 내 ip와 도메인 ip 가져오기 - Java code

Razelo 2020. 12. 18. 15:56
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();
			}
	}

}
반응형