V-CLASS 1 PEMROGRAMAN JARINGAN
10:44 PM
Modul 1
MENGETAHUI NAMA KOMPUTER LOKAL /SENDIRI
Program di bawah ini untuk mengetahui nama komputer lokal.
import java.net.*;
public class getName{
public static void main(String args[]) throws Exception{
InetAddress host = null ;
host = InetAddress.getLocalHost();
System.out.println("Nama komputer Anda :" + host.getHostName());
}
}
Output
Modul 2
MENGETAHUI NAMA KOMPUTER LOKAL /SENDIRI
program dibawah ini diberi nama IPtoName.java, program ini bertujuan untuk mendapatkan nama komputer dari Alamat IP.
import java.net.*;
public class IPtoName{
public static void main(String args[]){
if (args.length == 0){
System.out.println("Pemakaian : java IPtoName
System.exit(0);
}
String host = args[0] ;
InetAddress address = null ;
try{
address = InetAddress.getByName(host);
}catch(UnknownHostException e){
System.out.println("invalid IP");
System.exit(0);
}
System.out.println(address.getHostName());
}
}
Jalankan dengan argumen IP komputer lokal dan komputer lain.
$ javac IPtoName.java
$ java IPtoName
$ java IPtoName
$ java IPtoName
Output
Modul 3
MENGETAHUI IP ADDRESS DARI HOSTNAME
Buat program di bawah ini dan masukkan hostnamenya,maka akan menampilkan alamat IP nya
import java.net.*;
import java.io.*;
public class IPFinder{
public static void main(String args[]) throws IOException{
String host;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter host name : ");
host = input.readLine();
try{
InetAddress address = InetAddress.getByName(host);
System.out.println("IP Address : " + address);
}catch(UnknownHostException e){
System.out.println("Could not find " + host);
}
}
}
Output
Leave your comment