Kalkulator IP-1 Java


Skrip java untuk mencari IP network dan IP broadcast, ini masih sederhana perlu di kembangkan


// Dibuat oleh : Wahyudin
// Tegal, 8 April 2009
//=========================

import java.lang.Math;
import java.io.*;
public class ipkalkulator
{
public static void main( String[] args )
{
//Indentifikasi Variable
String Sipadress = "", Ssubnetmask = "";
String [] Soctafipadress = new String[4];
String [] Soctafsubnetmask = new String[4];
Double desbiner, pangkat,ipdesimal ;
int desimal,sisa,hasil,k,awal,akhir;
int [][] bineripadress = new int[4][8];
int [][] binersubnetmask = new int[4][8];
int [][] binerRsubnetmask = new int[4][8];
int [][] bineripnetwork = new int[4][8];
int [][] bineripbroadcast = new int[4][8];
Double [] ipbroadcast = new Double[4];
Double [] ipnetwork = new Double[4];

//Masukan Data
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in) );
String Sdesimal = "";
try
{
System.out.print("IP Adress (xxx.xxx.xxx.xxx) : "); Sipadress = dataIn.readLine();
System.out.print("Subnet Mask (xxx.xxx.xxx.xxx) : "); Ssubnetmask = dataIn.readLine();
}
catch(IOException e)
{
System.out.println("gagal membaca keyboard");
}

// Oktaf IP Adress
awal = 0;
akhir = 0;
for (int i=0; i<4 ; i++)
{
if (i == 3)
{
akhir = Sipadress.length();
} else
{
akhir = Sipadress.indexOf('.',akhir+i);
}
Soctafipadress[i] = Sipadress.substring(awal,akhir);
awal = akhir + 1 ;
}
// tampilan Octaf IP Adress

System.out.println("Info Alamat IP :");
System.out.print("IP Adress :");

for (int i=0; i<4 ; i++)
{
System.out.print(Soctafipadress[i]+".");
}

// Oktaf IP Subnet Mask
awal = 0;
akhir = 0;
for (int i=0; i<4 ; i++)
{
if (i == 3)
{
akhir = Ssubnetmask.length();
} else
{
akhir = Ssubnetmask.indexOf('.',akhir+i);
}

Soctafsubnetmask[i] = Ssubnetmask.substring(awal,akhir);
awal = akhir + 1 ;
}

// tampilan Octaf IP Subnet Mask
System.out.println();
System.out.print("Subnet Mask :");

for (int i=0; i<4 ; i++)
{
System.out.print(Soctafsubnetmask[i]+".");
}

// konversi Desimal ke biner IP Adress
System.out.println();
for (int j=0; j<4 ; j++)
{
k = 7;
hasil = Integer.parseInt(Soctafipadress[j]);
for( int i=0; i<8; i++ )
{
sisa = hasil%2;
bineripadress[j][k] = sisa;
k--;
hasil = (hasil-sisa)/2;
if (hasil == 0)
{
sisa = 0;
}
}
}
// tampilan bentuk huruf biner
System.out.println();
System.out.println("Menghitung IP Network : (IP Adress and Subnet Mask)");
System.out.println("===================================================");

System.out.print("IP Adress : ");

for (int j=0; j<4 ; j++)
{
for( int i=0; i<8; i++ )
{
System.out.print(bineripadress[j][i]);
}
System.out.print(".");
}

// konversi Desimal ke biner Subnet Mask
for (int j=0; j<4 ; j++)
{
k = 7;
hasil = Integer.parseInt(Soctafsubnetmask[j]);
for( int i=0; i<8; i++ )
{
sisa = hasil%2;
binersubnetmask[j][k] = sisa;
k--;
hasil = (hasil-sisa)/2;
if (hasil == 0)
{
sisa = 0;
}
}
}
// tampilan bentuk huruf biner
System.out.println();
System.out.print("Subnet Mask : ");
for (int j=0; j<4 ; j++)
{
for( int i=0; i<8; i++ )
{
System.out.print(binersubnetmask[j][i]);
}
System.out.print(".");
}

// IP Adress
System.out.println();
System.out.println("---------------------------------------------------------- AND ");
System.out.print("IP Network : ");

for (int j=0; j<4 ; j++)
{
for( int i=0; i<8; i++ )
{
bineripnetwork [j][i] = bineripadress[j][i] & binersubnetmask[j][i];
System.out.print(bineripnetwork[j][i]);
}
System.out.print(".");
}

// IP Adress Desimal
System.out.println();
System.out.print("IP Network : ");
for (int j=0; j<4 ; j++)
{
ipdesimal = 0.0;
pangkat = 7.0;
for( int i=0; i<8; i++ )
{
desbiner = Math.pow(2,pangkat);
ipdesimal = ipdesimal + desbiner * bineripnetwork[j][i] ;
pangkat = pangkat - 1.0;
}
ipnetwork [j] = ipdesimal;
System.out.print(Math.round(ipnetwork [j])+".");

}

// IP Broadcast
System.out.println();
System.out.println();
System.out.println("Menghitung IP Broadcast : (IP Network or Reverse Subnet Mask)");
System.out.println("=============================================================");

// IP Adress Desimal
System.out.println();
System.out.print("IP Network : ");
for (int j=0; j<4 ; j++)
{
for( int i=0; i<8; i++ )
{
System.out.print(bineripnetwork[j][i]);
}
System.out.print(".");
}

System.out.println();
System.out.print("Reverse Subnet Mask : ");

for (int j=0; j<4 ; j++)
{
for( int i=0; i<8; i++ )
{
if (binersubnetmask[j][i] == 1)
{
binerRsubnetmask [j][i] = 0;
} else
{
binerRsubnetmask [j][i] = 1;
}
bineripbroadcast [j][i] = bineripnetwork[j][i] | binerRsubnetmask[j][i];
System.out.print(binerRsubnetmask[j][i]);
}
System.out.print(".");
}

System.out.println();
System.out.println("----------------------------------------------------------- OR" );

System.out.print("IP Broadcast : ");
for (int j=0; j<4 ; j++)
{
for( int i=0; i<8; i++ )
{
System.out.print(bineripbroadcast[j][i]);
}
System.out.print(".");
}

// IP Adress Desimal
System.out.println();
System.out.print("IP Broadcast : ");
for (int j=0; j<4 ; j++)
{
ipdesimal = 0.0;
pangkat = 7.0;
for( int i=0; i<8; i++ )
{
desbiner = Math.pow(2,pangkat);
ipdesimal = ipdesimal + desbiner * bineripbroadcast[j][i] ;
pangkat = pangkat - 1.0;
}
ipbroadcast [j] = ipdesimal;
System.out.print(Math.round(ipbroadcast [j])+".");

}
System.out.println();
}
}

One thought on “Kalkulator IP-1 Java

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s