Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <string>
- #include <iostream>
- #include <sstream>
- #include <cstdlib>
- using namespace std;
- int main ()
- {
- int ip[3];
- char dot;
- char slash;
- int network;
- cout << "Type IP address: ";
- cin >> ip[0] >> dot >> ip[1] >> dot >> ip[2] >> dot >> ip[3];
- cout << "You typed: " << ip[0] << dot << ip[1] << dot << ip[2] << dot << ip[3];
- if (ip[0] > 0 && ip[0] <=127){
- cout << "\nIP: " << ip[0] <<dot << ip[1] <<dot << ip[2] <<dot << ip[3] <<" is class A-address and subnet mask by default is 255.0.0.0";
- }
- else if (ip[0] > 127 && ip[0] <= 191){
- cout << "\nIP: " << ip[0] <<dot << ip[1] <<dot << ip[2] <<dot << ip[3] <<" is class B-address and subnet mask by default is 255.255.0.0";
- }
- else if (ip[0] > 191 && ip[0] <= 223){
- cout << "\nIP: " << ip[0] <<dot << ip[1] <<dot << ip[2] <<dot << ip[3] <<" is class C-address and subnet mask by default is 255.255.255.0";
- }
- cout << "\nHow many bits in network part of the address: ";
- cin >> network;
- // A-luokan subnet maskit
- if (network >=8 && network <=30 && ip[0] < 127){
- if (network == 8){
- cout << "\nSubnet mask is: 255.0.0.0";
- }
- else if (network == 9){
- cout << "\nSubnet mask is 255.128.0.0";
- }
- else if (network == 10){
- cout << "\nSubnet mask is 255.192.0.0";
- }
- else if (network == 11){
- cout << "\nSubnet mask is 255.224.0.0";
- }
- else if (network == 12){
- cout << "\nSubnet mask is 255.224.0.0";
- }
- else if (network == 13){
- cout << "\nSubnet mask is 255.248.0.0";
- }
- else if (network == 14){
- cout << "\nSubnet mask is 255.252.0.0";
- }
- else if (network == 15){
- cout << "\nSubnet mask is 255.254.0.0";
- }
- else if (network == 16){
- cout << "\nSubnet mask is 255.255.0.0";
- }
- else if (network == 17){
- cout << "\nSubnet mask is 255.255.128.0";
- }
- else if (network == 18){
- cout << "\nSubnet mask is 255.255.192.0";
- }
- else if (network == 19){
- cout << "\nSubnet mask is 255.255.224.0";
- }
- else if (network == 20){
- cout << "\nSubnet mask is 255.255.240.0";
- }
- else if (network == 21){
- cout << "\nSubnet mask is 255.255.248.0";
- }
- else if (network == 22){
- cout << "\nSubnet mask is 255.255.252.0";
- }
- else if (network == 23){
- cout << "\nSubnet mask is 255.255.254.0";
- }
- else if (network == 24){
- cout << "\nSubnet mask is 255.255.255.0";
- }
- else if (network == 25){
- cout << "\nSubnet mask is 255.255.255.128";
- }
- else if (network == 26){
- cout << "\nSubnet mask is 255.255.255.192";
- }
- else if (network == 27){
- cout << "\nSubnet mask is 255.255.255.224";
- }
- else if (network == 28){
- cout << "\nSubnet mask is 255.255.255.240";
- }
- else if (network == 29){
- cout << "\nSubnet mask is 255.255.255.248";
- }
- else if (network == 30){
- cout << "\nSubnet mask is 255.255.255.252";
- }
- }
- // B-luokan subnet maskit
- else if (network >=16 && network <=30 && ip[0] <= 191){
- if (network == 16){
- cout << "\nSubnet mask is 255.255.0.0";
- }
- else if (network == 17){
- cout << "\nSubnet mask is 255.255.128.0";
- }
- else if (network == 18){
- cout << "\nSubnet mask is 255.255.192.0";
- }
- else if (network == 19){
- cout << "\nSubnet mask is 255.255.224.0";
- }
- else if (network == 20){
- cout << "\nSubnet mask is 255.255.240.0";
- }
- else if (network == 21){
- cout << "\nSubnet mask is 255.255.248.0";
- }
- else if (network == 22){
- cout << "\nSubnet mask is 255.255.252.0";
- }
- else if (network == 23){
- cout << "\nSubnet mask is 255.255.254.0";
- }
- else if (network == 24){
- cout << "\nSubnet mask is 255.255.255.0";
- }
- else if (network == 25){
- cout << "\nSubnet mask is 255.255.255.128";
- }
- else if (network == 26){
- cout << "\nSubnet mask is 255.255.255.192";
- }
- else if (network == 27){
- cout << "\nSubnet mask is 255.255.255.224";
- }
- else if (network == 28){
- cout << "\nSubnet mask is 255.255.255.240";
- }
- else if (network == 29){
- cout << "\nSubnet mask is 255.255.255.248";
- }
- else if (network == 30){
- cout << "\nSubnet mask is 255.255.255.252";
- }
- }
- // C-luokan subnet maskit
- if (network >=24 && network <=30 && ip[0] <= 223){
- if (network == 24){
- cout << "\nSubnet mask is 255.255.255.0";
- }
- else if (network == 25){
- cout << "\nSubnet mask is 255.255.255.128";
- }
- else if (network == 26){
- cout << "\nSubnet mask is 255.255.255.192";
- }
- else if (network == 27){
- cout << "\nSubnet mask is 255.255.255.224";
- }
- else if (network == 28){
- cout << "\nSubnet mask is 255.255.255.240";
- }
- else if (network == 29){
- cout << "\nSubnet mask is 255.255.255.248";
- }
- else if (network == 30){
- cout << "\nSubnet mask is 255.255.255.252";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement