Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ipaddress;
- import java.util.StringTokenizer;
- import javax.swing.JOptionPane;
- import java.lang.Math;
- public class Main {
- public static void main(String[] args) {
- String adres = "";
- adres = JOptionPane.showInputDialog("Podaj adres wraz z maską sieci");
- StringTokenizer adres1 = new StringTokenizer(adres, "./");
- int ileSieci = Integer.parseInt(JOptionPane.showInputDialog("Podaj liczbę podsieci"));
- int ileHostow = Integer.parseInt(JOptionPane.showInputDialog("Podaj liczbę hostów"));
- int p1 = 0;
- int p2 = 0;
- int p3 = 0;
- int p4 = 0;
- int mask = 0;
- if (adres1.hasMoreTokens()) {
- p1 = Integer.parseInt(adres1.nextToken());
- System.out.println(p1);
- }
- if (adres1.hasMoreTokens()) {
- p2 = Integer.parseInt(adres1.nextToken());
- System.out.println(p2);
- }
- if (adres1.hasMoreTokens()) {
- p3 = Integer.parseInt(adres1.nextToken());
- System.out.println(p3);
- }
- if (adres1.hasMoreTokens()) {
- p4 = Integer.parseInt(adres1.nextToken());
- System.out.println(p4);
- }
- if (adres1.hasMoreTokens()) {
- mask = Integer.parseInt(adres1.nextToken());
- System.out.println(mask);
- if (mask == 8) {
- System.out.println("klasa A");
- } else if (mask == 16) {
- System.out.println("klasa B");
- } else if (mask == 24) {
- System.out.println("klasa C");
- int potega = 1;
- int jakaPotega = 8;
- while (potega < ileSieci) {
- potega *= 2;
- jakaPotega--;
- }
- potega -= 2;
- int koniec = (int) (256 - (Math.pow(2, jakaPotega)));
- String maskaPodsieci = 255 + "." + 255 + "." + 255 + "." + koniec;
- System.out.println(maskaPodsieci);
- int ile = 0;
- for (int i = 0; i < ileSieci; i++) {
- System.out.println("Adres sieci:\n" + p1 + "." + p2 + "." + p3 + "." + ile);
- System.out.println("Adresy hostów:\n");
- for (int j = 1; j < ileHostow; j++) {
- System.out.println(p1 + "." + p2 + "." + p3 + "." + j);
- }
- System.out.println("Adres Broadcastu:\n" + p1 + "." + p2 + "." + p3 + "." + ileHostow);
- }
- } else {
- System.out.println("Podałeś złą maskę");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment