Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4. #include <sstream>
  5. #include <cstdlib>
  6. using namespace std;
  7.  
  8. int main ()
  9. {
  10. int ip[3];
  11. char dot;
  12. char slash;
  13. int network;
  14.  
  15. cout << "Type IP address: ";
  16. cin >> ip[0] >> dot >> ip[1] >> dot >> ip[2] >> dot >> ip[3];
  17. cout << "You typed: " << ip[0] << dot << ip[1] << dot << ip[2] << dot << ip[3];
  18.  
  19. if (ip[0] > 0 && ip[0] <=127){
  20. 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";
  21. }
  22. else if (ip[0] > 127 && ip[0] <= 191){
  23. 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";
  24. }
  25. else if (ip[0] > 191 && ip[0] <= 223){
  26. 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";
  27. }
  28.  
  29.  
  30. cout << "\nHow many bits in network part of the address: ";
  31. cin >> network;
  32.  
  33. // A-luokan subnet maskit
  34.  
  35. if (network >=8 && network <=30 && ip[0] < 127){
  36.  
  37. if (network == 8){
  38. cout << "\nSubnet mask is: 255.0.0.0";
  39. }
  40. else if (network == 9){
  41. cout << "\nSubnet mask is 255.128.0.0";
  42. }
  43. else if (network == 10){
  44. cout << "\nSubnet mask is 255.192.0.0";
  45. }
  46. else if (network == 11){
  47. cout << "\nSubnet mask is 255.224.0.0";
  48. }
  49. else if (network == 12){
  50. cout << "\nSubnet mask is 255.224.0.0";
  51. }
  52. else if (network == 13){
  53. cout << "\nSubnet mask is 255.248.0.0";
  54. }
  55. else if (network == 14){
  56. cout << "\nSubnet mask is 255.252.0.0";
  57. }
  58. else if (network == 15){
  59. cout << "\nSubnet mask is 255.254.0.0";
  60. }
  61. else if (network == 16){
  62. cout << "\nSubnet mask is 255.255.0.0";
  63. }
  64. else if (network == 17){
  65. cout << "\nSubnet mask is 255.255.128.0";
  66. }
  67. else if (network == 18){
  68. cout << "\nSubnet mask is 255.255.192.0";
  69. }
  70. else if (network == 19){
  71. cout << "\nSubnet mask is 255.255.224.0";
  72. }
  73. else if (network == 20){
  74. cout << "\nSubnet mask is 255.255.240.0";
  75. }
  76. else if (network == 21){
  77. cout << "\nSubnet mask is 255.255.248.0";
  78. }
  79. else if (network == 22){
  80. cout << "\nSubnet mask is 255.255.252.0";
  81. }
  82. else if (network == 23){
  83. cout << "\nSubnet mask is 255.255.254.0";
  84. }
  85. else if (network == 24){
  86. cout << "\nSubnet mask is 255.255.255.0";
  87. }
  88. else if (network == 25){
  89. cout << "\nSubnet mask is 255.255.255.128";
  90. }
  91. else if (network == 26){
  92. cout << "\nSubnet mask is 255.255.255.192";
  93. }
  94. else if (network == 27){
  95. cout << "\nSubnet mask is 255.255.255.224";
  96. }
  97. else if (network == 28){
  98. cout << "\nSubnet mask is 255.255.255.240";
  99. }
  100. else if (network == 29){
  101. cout << "\nSubnet mask is 255.255.255.248";
  102. }
  103. else if (network == 30){
  104. cout << "\nSubnet mask is 255.255.255.252";
  105. }
  106.  
  107.  
  108. }
  109.  
  110. // B-luokan subnet maskit
  111. else if (network >=16 && network <=30 && ip[0] <= 191){
  112.  
  113. if (network == 16){
  114. cout << "\nSubnet mask is 255.255.0.0";
  115. }
  116. else if (network == 17){
  117. cout << "\nSubnet mask is 255.255.128.0";
  118. }
  119. else if (network == 18){
  120. cout << "\nSubnet mask is 255.255.192.0";
  121. }
  122. else if (network == 19){
  123. cout << "\nSubnet mask is 255.255.224.0";
  124. }
  125. else if (network == 20){
  126. cout << "\nSubnet mask is 255.255.240.0";
  127. }
  128. else if (network == 21){
  129. cout << "\nSubnet mask is 255.255.248.0";
  130. }
  131. else if (network == 22){
  132. cout << "\nSubnet mask is 255.255.252.0";
  133. }
  134. else if (network == 23){
  135. cout << "\nSubnet mask is 255.255.254.0";
  136. }
  137. else if (network == 24){
  138. cout << "\nSubnet mask is 255.255.255.0";
  139. }
  140. else if (network == 25){
  141. cout << "\nSubnet mask is 255.255.255.128";
  142. }
  143. else if (network == 26){
  144. cout << "\nSubnet mask is 255.255.255.192";
  145. }
  146. else if (network == 27){
  147. cout << "\nSubnet mask is 255.255.255.224";
  148. }
  149. else if (network == 28){
  150. cout << "\nSubnet mask is 255.255.255.240";
  151. }
  152. else if (network == 29){
  153. cout << "\nSubnet mask is 255.255.255.248";
  154. }
  155. else if (network == 30){
  156. cout << "\nSubnet mask is 255.255.255.252";
  157. }
  158.  
  159.  
  160. }
  161.  
  162. // C-luokan subnet maskit
  163.  
  164. if (network >=24 && network <=30 && ip[0] <= 223){
  165.  
  166. if (network == 24){
  167. cout << "\nSubnet mask is 255.255.255.0";
  168. }
  169. else if (network == 25){
  170. cout << "\nSubnet mask is 255.255.255.128";
  171. }
  172. else if (network == 26){
  173. cout << "\nSubnet mask is 255.255.255.192";
  174. }
  175. else if (network == 27){
  176. cout << "\nSubnet mask is 255.255.255.224";
  177. }
  178. else if (network == 28){
  179. cout << "\nSubnet mask is 255.255.255.240";
  180. }
  181. else if (network == 29){
  182. cout << "\nSubnet mask is 255.255.255.248";
  183. }
  184. else if (network == 30){
  185. cout << "\nSubnet mask is 255.255.255.252";
  186. }
  187.  
  188. }
  189.  
  190.  
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement