Wednesday, October 10, 2012

Program Java Sederhana Melihat IP Address


Program java sederhana untuk melihat IP Address.
Jalankan netbeans agan pilih file/New Project/Java/Java Application. Lalu klik next. Untuk project name nya terserah agan mau buat apa :D kemudian klik finish. Copas script java di bawah ini :

          Main.java
package javaapplication8;
import java.net.*;
public class Main {
    public static void main(String[]args)  {
        // TODO code application logic here
        try {
        InetAddress addr = InetAddress.getLocalHost();
        if(addr!=null){
            System.out.println("IP Address:" + addr.getHostAddress());
            System.out.println("Hostname:" + addr.getHostName());
            System.out.println("Loopback:" + addr.isLoopbackAddress());
    }
}
       catch(UnknownHostException e){
           System.out.println(e.getMessage());
       }
}
}

Kemudian Run atau Debug projectnya.
Selamat mencoba!! Semoga Berhasil....
Disqus Comments