Programming, tutorials, mechatronics, operating systems, and other tech stuff

How to make ip address calculator with java netbeans

6 comments

This one is a video tutorial. And here is the source code which is used in the tutorial.
For step-by-step instruction, please watch the video.


int prefix = Integer.valueOf(mask.getText());
int pos = prefix / 8; //important octet position
int rem = prefix % 8; //binary digit of importan octet

String binIpFull = "";
String subBinary = "";
String subBinaryFull = "";
String binnetidFull = "";
String binbcidFull = "";
String netmaskFull = "";
String netidFull = "";
String bcidFull = "";

//loop to generate binary mask from octet pos
for (int i = 1; i & lt; = 8; i++) {
 if (i & lt; = rem) {
  subBinary += "1";
 } else {
  subBinary += "0";
 }
}

//netmask (integer version of subBinary
int netmask = Integer.parseInt(String.valueOf(subBinary), 2);

//ip octets array
int[] oct = {
 Integer.valueOf(oct1.getText()),
 Integer.valueOf(oct2.getText()),
 Integer.valueOf(oct3.getText()),
 Integer.valueOf(oct4.getText())
};

//binary of important octet
String binOct = String.format("%8s", Integer.toBinaryString(oct[pos])).replace(' ', '0');

String binNetId = "";
String binBcId = "";

for (int i = 0; i & lt; 8; i++) {
 String binPointer = subBinary.substring(i, i + 1);
 if (binPointer.equals("1")) {
  binNetId += binOct.substring(i, i + 1);
  binBcId += binOct.substring(i, i + 1);
 } else {
  binNetId += "0";
  binBcId += "1";
 }
}

//loop to generate display-ready strings
for (int i = 0; i & lt; = 3; i++) {
 binIpFull += String.format("%8s", Integer.toBinaryString(oct[i])).replace(' ', '0');
 if (i < pos) { = ""
  subbinaryfull += "11111111"; = ""
  netmaskfull = "" += "255"
  binnetidfull = ""
  ','
  0 ');="" binbcidfull="" netidfull="" bcidfull="" ="" }else="" if(i="">pos){
  subBinaryFull += "00000000";
  netmaskFull += "0";
  binnetidFull += "00000000";
  binbcidFull += "00000000";
  netidFull += "0";
  bcidFull += "1";
 } else {
  subBinaryFull += subBinary;
  netmaskFull += String.valueOf(netmask);
  binnetidFull += binNetId;
  binbcidFull += binBcId;
  netidFull += Integer.parseInt(String.valueOf(binNetId), 2);
  bcidFull += Integer.parseInt(String.valueOf(binBcId), 2);
 }
 if (i != 3) {
  subBinaryFull += ".";
  netmaskFull += ".";
  binnetidFull += ".";
  binbcidFull += ".";
  netidFull += ".";
  bcidFull += ".";
  binIpFull += ".";
 }
}
subBinLabel.setText(subBinaryFull);
netMaskLabel.setText(netmaskFull);
netBinLabel.setText(binnetidFull);
bcBinLabel.setText(binbcidFull);
netIdLabel.setText(netidFull);
bcIdLabel.setText(bcidFull);
ipBinLabel.setText(binIpFull);


You can watch the video here:



6 comments :

  1. Great job.... Awesome list, just starting a blog and this is going to be a massive help. Thank you!

    Node JS Training in Chennai
    Node JS Training

    ReplyDelete
  2. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. https://192-168-i-i.com

    ReplyDelete
  3. The writer has written this blog in a very idiomatic manner.
    mortgage calculator

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. IP delivers are doled out to a host either over again after booting time or for all time through fixed design of its product or equipment. Utilizing a "static Internet Protocol address" signifies diligent design. Utilizing a "unique Internet Protocol address," then again, is doling out a PC's location from time to time. 192.168.l0.1

    ReplyDelete
  6. Always get the most effective suite charges, exclusive resort access, comps for gaming play, and more. You’ll just must activate your on-line account utilizing your Grazie Rewards account number and PIN. By submitting this kind, would 카지노 possibly be} giving your consent for Crescent School of Gaming and Bartending to contact you relating to our applications and companies.

    ReplyDelete