Friday, November 13, 2015

Consider the network id 192.168.4.0 and create four subnets namely A, B, C, D. Assign the subnet mask. Write a Python \ C++ program to Perform the following operations (use overloading if applicable). a) Ping the machine of same subnet. b) Ping the machine in subnet A from machine of subnet B. c) Analyse the output of the above sub assignments.

Program

#include <iostream>
#include <stdio.h>
#include <string.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

#include<unistd.h>

using namespace std;

class asg2
{
            string ip;
            int same;
            int diff;

public:
            void same_subnet();
            void diff_subnet();
            void analysis(int b);
};

int main()
{
            asg2 ob;
            int choice;
        cout<<"Subnet mask: 255.255.255.192"<<endl;
        cout<<"IP address range:"<<endl;
        cout<<"subnet A- 192.168.4.0 - 192.168.4.63"<<endl;
        cout<<"subnet B- 192.168.4.64 - 192.168.4.127"<<endl;
        cout<<"subnet C- 192.168.4.128 - 192.168.4.191"<<endl;
        cout<<"subnet D- 192.168.4.192 - 192.168.4.255"<<endl;
            do{
                        cout<<"1.Ping the machine of same subnet"<<endl;
                        cout<<"2.Ping the machine of different subnet"<<endl;
                        cout<<"Enter choice:";
                        cin>>choice;
                        switch(choice)
                        {
                                    case 1: ob.same_subnet();
                                                break;
                                    case 2: ob.diff_subnet();
                                                break;
                        }
            }while(choice!=3);
            return 0;
}

void asg2::same_subnet()
{         
            string cmd;
            cout<<"Enter IP address to PING: ";
            cin>>ip;
            cmd="ping "+ip;
            system(cmd.c_str());
            same=system(cmd.c_str());
            analysis(same);

}

void asg2::diff_subnet()
{
            string cmd;
            cout<<"Enter IP address to PING=";
            cin>>ip;
            cmd="ping "+ip;
            system(cmd.c_str());
        diff=system(cmd.c_str());
            analysis(diff);
}

void asg2::analysis(int res)
{
            if(res==0)
            {
                        cout<<"Successful PING.Machine in same subnet"<<endl;
                cout<<"IP address: "<<ip<<endl;

            }
            else if(res==256)
            {
                        cout<<"Machine in the same is shutdown"<<endl;
                cout<<"IP address: "<<ip<<endl;

            }

            else if(res==512)
            {
                        cout<<"Machine in another subnet"<<endl;
                cout<<"IP address: "<<ip<<endl;
            }


}


Output

[exam10@localhost 3206]$ g++ asg2.cpp
[exam10@localhost 3206]$ ./a.out
Subnet mask: 255.255.255.192
IP address range:
subnet A- 192.168.4.0 - 192.168.4.63
subnet B- 192.168.4.64 - 192.168.4.127
subnet C- 192.168.4.128 - 192.168.4.191
subnet D- 192.168.4.192 - 192.168.4.255
1.Ping the machine of same subnet
2.Ping the machine of different subnet
Enter choice:1
Enter IP address to PING: 192.168.4.45
PING 192.168.4.45 (192.168.4.45) 56(84) bytes of data.
64 bytes from 192.168.4.45: icmp_seq=1 ttl=64 time=0.170 ms
64 bytes from 192.168.4.45: icmp_seq=2 ttl=64 time=0.226 ms
64 bytes from 192.168.4.45: icmp_seq=3 ttl=64 time=0.158 ms
64 bytes from 192.168.4.45: icmp_seq=4 ttl=64 time=0.225 ms
^C
--- 192.168.4.45 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.158/0.194/0.226/0.035 ms
PING 192.168.4.45 (192.168.4.45) 56(84) bytes of data.
64 bytes from 192.168.4.45: icmp_seq=1 ttl=64 time=0.266 ms
64 bytes from 192.168.4.45: icmp_seq=2 ttl=64 time=0.226 ms
64 bytes from 192.168.4.45: icmp_seq=3 ttl=64 time=0.152 ms
64 bytes from 192.168.4.45: icmp_seq=4 ttl=64 time=0.216 ms
^C
--- 192.168.4.45 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.152/0.215/0.266/0.040 ms
Successful PING.Machine in same subnet
IP address: 192.168.4.45
1.Ping the machine of same subnet
2.Ping the machine of different subnet
Enter choice:2
Enter IP address to PING=192.168.4.89
connect: Network is unreachable
connect: Network is unreachable
Machine in another subnet
IP address: 192.168.4.89
1.Ping the machine of same subnet
2.Ping the machine of different subnet
Enter choice:1
Enter IP address to PING: 192.168.4.63
Do you want to ping broadcast? Then -b
Do you want to ping broadcast? Then -b
Machine in another subnet
IP address: 192.168.4.63
1.Ping the machine of same subnet
2.Ping the machine of different subnet
Enter choice:1
Enter IP address to PING: 192.168.4.62
PING 192.168.4.62 (192.168.4.62) 56(84) bytes of data.
From 192.168.4.50 icmp_seq=1 Destination Host Unreachable
From 192.168.4.50 icmp_seq=2 Destination Host Unreachable
From 192.168.4.50 icmp_seq=3 Destination Host Unreachable
From 192.168.4.50 icmp_seq=4 Destination Host Unreachable
^C
--- 192.168.4.62 ping statistics ---
7 packets transmitted, 0 received, +4 errors, 100% packet loss, time 6001ms
pipe 4
PING 192.168.4.62 (192.168.4.62) 56(84) bytes of data.
^C
--- 192.168.4.62 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

Machine in the same is shutdown
IP address: 192.168.4.62
1.Ping the machine of same subnet
2.Ping the machine of different subnet

No comments:

Post a Comment

Perform a suitable assignment using Xen Hypervisor or equivalent open source to configure it. Give necessary GUI.

 To install kvm on Fedora:  yum install kvm  yum install virt-manager libvirt libvirt-python python-virtinst  su -c "yum install @v...