KEMBAR78
IP Addressing & Subnetting Guide | PDF | Internet Protocols | Communications Protocols
0% found this document useful (0 votes)
73 views6 pages

IP Addressing & Subnetting Guide

The document is a student assignment submission for a networking and communication course, covering the topic of classless IP addressing. It includes code to take an IP address and subnet mask as input, calculate the binary representation, and determine the first address, last address, and total number of addresses in the subnet. The code then implements subnetting concepts for an organization by taking the organization's address and mask, number of subnets needed, and addresses required for each subnet to output the subnet ranges.

Uploaded by

Yash Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views6 pages

IP Addressing & Subnetting Guide

The document is a student assignment submission for a networking and communication course, covering the topic of classless IP addressing. It includes code to take an IP address and subnet mask as input, calculate the binary representation, and determine the first address, last address, and total number of addresses in the subnet. The code then implements subnetting concepts for an organization by taking the organization's address and mask, number of subnets needed, and addresses required for each subnet to output the subnet ranges.

Uploaded by

Yash Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ASSIGNMENT-4

SUBJECT: NETWORK AND COMMUNICATION

SUBJECT CODE: CSE1004

SUBMITTED BY:

NAME: PATEL YASH VIJAYKUMAR


REGISTRATION NUMBER: 17BCE0335
LAB SLOT: L7+L8

SUBMITTED TO:

PROF. MANIKANDAN N

TOPICS COVERED: CLASSLESS IP ADDRESSING


AIM : TO CALCULATE FIRST ADDRESS,LAST ADDRESS AND
NUMBER OF ADDRESS

CODE:

#include<stdio.h>
#include<math.h>
int main()
{
int ip[4],n,i,j,s,t,sum;
printf("Enter the IP address with mask value in xxx.xxx.xxx.xxx/n
format: ");
scanf("%d.%d.%d.%d/%d",&ip[0],&ip[1],&ip[2],&ip[3],&n);
//printf("%d %d %d %d %d",ip[0],ip[1],ip[2],ip[3],n);
int binary[4][8];
for(i=0;i<4;i++)
{
s=ip[i];
for(t=0;t<8;t++)
{
binary[i][7-t]=s%2;
s=s/2;
}
}
int k=32-n;
j=0,t=0;
for(i=0;i<k;i++)
{
if(j!=8)
{
binary[3-t][7-j]=0;
j++;
}
else
{
j=0;
t++;
binary[3-t][7-j]=0;
j++;
}

}
int first_addr[4],last_addr[4];
for(i=0;i<4;i++)
{
sum=0;
for(j=0;j<8;j++)
{
sum+=binary[i][7-j]*(pow(2,j));
}
first_addr[i]=sum;
}
printf("\n the first address is: ");
for(i=0;i<4;i++)
{
printf(".%d",first_addr[i]);
}
for(i=0;i<4;i++)
{
s=ip[i];
for(t=0;t<8;t++)
{
binary[i][7-t]=s%2;
s=s/2;
}
}
j=0,t=0;
for(i=0;i<k;i++)
{
if(j!=8)
{
binary[3-t][7-j]=1;
j++;
}
else
{
j=0;
t++;
binary[3-t][7-j]=1;
j++;
}

}
for(i=0;i<4;i++)
{
sum=0;
for(j=0;j<8;j++)
{
sum+=binary[i][7-j]*(pow(2,j));
}
last_addr[i]=sum;
}
printf("\n the last address is: ");
for(i=0;i<4;i++)
{
printf(".%d",last_addr[i]);
}
n=pow(2,k);
printf("\n The total no of addresses are: %d ",n);

OUTPUT:
AIM : IMPLEMENTING SUBNETTING CONCEPTS FOR
ORGANISATION

CODE:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int a,b,c,d,q[15],n;
double x = 2.0,k,m;
cout<<"\nEnter address for organisation : ";
cin>>a>>b>>c>>d;
cout<<"\nEnter subnet mask for organisation : ";
cin>>m;
cout<<"\nAddress for
organisation :"<<a<<"."<<b<<"."<<c<<"."<<d<<"/"<<m<<endl;
cout<<"\nEnter Number of subnets : ";
cin>>n;
int i;
for(i=0;i<n;i++)
{
cout<<"\nHow many addresses for subnet "<<i+1<<" : ";
cin>>q[i];
}
for(i=0;i<n;i++)
{
m=0;
k=(int)pow(x,m);
while(k!=q[i])
{
m++;
k=(int)pow(x,m);
}
m=32-m;
if(d>255)
{
d=0;
c++;
}
cout<<"\nsubnet "<<i+1<<" : "<<a<<"."<<b<<"."<<c<<"."<<d<<"/"<<m;
d=d+q[i]-1;
if(d>255)
{
d=d-255-1;
c++;
}
cout<<" to "<<a<<"."<<b<<"."<<c<<"."<<d++<<"/"<<m;
}
return 0;
}

OUTPUT:

You might also like