Lab Programs
Lab Programs
Lab Programs
**Title:** ECLIPSE
**Steps to be followed to use eclipse:**
**Step 1:**
- File → New → Java Project → File name → Finish
**Step 2:**
- Window → Show views → Package Explorer → File name → New
→ Class → Class name
**Program:**
```java
package computer.net;
class computernet {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
```
1. **ifcon g**
**Syntax:** ifcon g
`ifcon g etho <address> netmask <address>`
2. **ip**
**Syntax:** `ip a`, `ip add`
3. **traceroute**
**Syntax:** `traceroute <destination>`
`$ traceroute -n google.com`
4. **tracepath**
**Syntax:** `tracepath <destination>`
`tracepath mindmajix.com`
5. **ping**
**Syntax:** `ping <destination>`
`$ ping google.com`
6. **netstat**
fi
fi
fi
fi
fi
**Syntax:** `netstat`
`netstat -p`, `netstat -s`, `netstat -r`
7. **ss**
**Syntax:** `ss`
`ss -ta`, `ss -ua`, `ss -xa`
8. **dig**
**Syntax:** `dig <domain name>`
`$ dig google.com`
9. **nslookup**
**Syntax:** `nslookup <domain name>`
10. **route**
**Syntax:** `route`
`route -n`, `route -cn`
11. **arp**
**Syntax:** `arp`
`arp -n`, `arp -d HWADDR`
13. **hostname**
**Syntax:** `hostname`
`sudo hostname <new name>`
17) mtr
Syntax: mtr <path>
18) if plugstatus
Sudo apt-get install ifplugd
Syntax: ifplugstatus
19) iftop:
tcpdump
Syntax: $tcpdump -i <network -device>
fi
fi
fi
fi
Lab Programs
1.LeakyBucket
package leaky;
import java.io.*;
public class program1 {
SOURCE CODE:
import java.io.*;
public class CRC {
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int[] data;
int[] div;
int[] divisor;
int[] rem;
int[] crc;
int data_bits, divisor_bits, tot_length;
System.out.println("Enter number of data bits : ");
data_bits=Integer.parseInt(br.readLine());
data=new int[data_bits];
System.out.println("Enter data bits : ");
for(int i=0; i<data_bits; i++)
data[i]=Integer.parseInt(br.readLine());
System.out.println("Enter number of bits in divisor : ");
divisor_bits=Integer.parseInt(br.readLine()); divisor=new
int[divisor_bits]; System.out.println("Enter Divisor bits : ");
for(int i=0; i<divisor_bits; i++)
divisor[i]=Integer.parseInt(br.readLine());
tot_length=data_bits+divisor_bits-1;
div=new int[tot_length];
rem=new int[tot_length];
crc=new int[tot_length];
/* CRC GENERATION */
System.out.println("data length is "+data.length);
for(int i=0;i<data.length;i++)
div[i]=data[i];
System.out.print("Dividend (after appending 0's) are : ");
for(int i=0; i< div.length; i++)
System.out.print(div[i]);
System.out.println();
for(int j=0; j<div.length; j++){
rem[j] = div[j];
}
rem=divide(div, divisor, rem);
for(int i=0;i<div.length;i++) // append dividend and remainder
{
crc[i]=(div[i]^rem[i]);
}
System.out.println();
System.out.println("CRC code : ");
for(int i=0;i<crc.length;i++)
System.out.print(crc[i]);
/* ERROR DETECTION */
System.out.println();
System.out.println("Enter CRC code of "+tot_length+" bits : ");
for(int i=0; i<crc.length; i++)
crc[i]=Integer.parseInt(br.readLine());
{
System.out.println("Data is incorrect!");
break;
}
if (i==rem.length-1)
System.out.println("Data is correct");
}
}
static int[] divide(int div[],int divisor[], int rem[])
{
int cur=0;
while(true)
{
for(int i=0;i<divisor.length;i++)
rem[cur+i]=(rem[cur+i]^divisor[i]);
if((rem.length-cur)<divisor.length)
break;
}
return rem;
}}
OUTPUT
Case 1:
Enter number of bits
16
Enter the data
1
1
1
1
1
1
1
0
0
0
1
0
0
0
1
0
Enter the divisor bits
1
1
0
1
Data length is 16
Dividend after appending 0’s are
1
1
1
1
1
1
1
0
0
0
1
0
0
0
1
0
0
0
0
CRC CODE
1111111000100010101
Enter CRC Code of 19 bits
1
1
1
1
1
1
1
0
0
0
1
0
0
0
1
0
1
0
1
Data is correct
Case-2
Enter number of bits
16
Enter the data
1
1
1
1
1
1
1
0
0
0
1
0
0
0
1
0
Enter the divisor bits
1
1
0
1
Data length is 16
Dividend after appending 0’s are
1
1
1
1
1
1
1
0
0
0
1
0
0
0
1
0
0
0
0
CRC CODE
1111111000100010101
Enter CRC Code of 19 bits
1
0
1
1
1
1
1
0
0
0
1
0
0
0
1
0
1
0
1
Data is incorrect
3.Hamming
#include <stdio.h>
#include <math.h>
int input[32];
int code[32];
int ham_calc(int,int);
void main()
{
int n,i,p_n = 0,c_l,j,k;
printf("Please enter the length of the Data Word: ");
scanf("%d",&n);
printf("Please enter the Data Word:\n");
for(i=0;i<n;i++)
{
scanf("%d",&input[i]);
}
i=0;
while(n>(int)pow(2,i)-(i+1))
{
p_n++;
i++;
}
c_l = p_n + n;
j=k=0;
for(i=0;i<c_l;i++)
{
if(i==((int)pow(2,k)-1))
{
code[i]=0;
k++;
}
else
{
code[i]=input[j];
j++;
}
}
for(i=0;i<p_n;i++)
{
int position = (int)pow(2,i);
int value = ham_calc(position,c_l);
code[position-1]=value;
}
printf("\nThe calculated Code Word is: ");
for(i=0;i<c_l;i++)
printf("%d",code[i]);
printf("\n");
printf("Please enter the received Code Word:\n");
for(i=0;i<c_l;i++)
scanf("%d",&code[i]);
int error_pos = 0;
for(i=0;i<p_n;i++)
{
int position = (int)pow(2,i);
int value = ham_calc(position,c_l);
if(value != 0)
error_pos+=position;
}
if(error_pos == 1)
printf("The received Code Word is correct.\n");
else
printf("Error at bit position: %d\n",error_pos);
}
int ham_calc(int position,int c_l)
{
int count=0,i,j;
i=position-1;
while(i<c_l)
{
for(j=i;j<i+position;j++)
{
if(code[j] == 1)
count++;
}
i=i+2*position;
}
if(count%2 == 0)
return 0;
else
return 1;
}
OUTPUT:
Chat Server
import java.net.*;
import java.io.*;
public class Server
{
private Socket socket = null;
private ServerSocket server = null;
private DataInputStream in = null;
public Server(int port)
{
try
{
server = new ServerSocket(port);
System.out.println("Server started");
System.out.println("Waiting for a client ...");
socket = server.accept();
System.out.println("Client accepted");
in = new DataInputStream( new BufferedInputStream(socket.getInputStream()));
String line = "";
while (!line.equals("Over"))
{
try
{
line = in.readUTF();
System.out.println(line);
}
catch(IOException i)
{
System.out.println(i);
}
}
System.out.println("Closing connection");
socket.close();
in.close();
}
catch(IOException i)
{
System.out.println(i);
}
}
public static void main(String args[])
{
Server server = new Server(5000);
}
}
Chat Client
import java.net.*;
import java.io.*;
public class Client
{
private Socket socket = null;
private DataInputStream input = null;
private DataOutputStream out = null;
public Client(String address, int port)
{
try
{
socket = new Socket(address, port);
System.out.println("Connected");
input = new DataInputStream(System.in);
out = new DataOutputStream(socket.getOutputStream());
}
catch(UnknownHostException u)
{
System.out.println(u);
}
catch(IOException i)
{
System.out.println(i);
}
String line = "";
while (!line.equals("Over"))
{
try
{
line = input.readLine();
out.writeUTF(line);
}
catch(IOException i)
{
System.out.println(i);
}
}
try
{
input.close();
out.close();
socket.close();
}
catch(IOException i)
{
System.out.println(i);
}
}
public static void main(String args[])
{
Client client = new Client("127.0.0.1", 5000);
}
}
OUTPUT:
Server:
Server started
Waiting for a client …
Client accepted
Client:
Connected
Server accepts the client
Input from client
Hello
I made my first socket connection
Over
Display at the server
Hello
I made my first socket connection
Over
Closing connection
12/08/2024, 09:42 1.jpg
https://classroom.google.com/c/NjYyNjU2NjEyMjkz/m/Njc4MTE1NDY0NDMw/details 1/1
12/08/2024, 09:43 2.jpg
https://classroom.google.com/c/NjYyNjU2NjEyMjkz/m/Njc4MTE1NDY0NDMw/details 1/1
6.CRC
#include<stdio.h>
#include<string.h>
char t[28],cs[28],g[]="1011";
int a,e,c;
void xor()
{
for(c = 1;c < N; c++)
cs[c] = (( cs[c] == g[c])?'0':'1');
}
void crc()
{
for(e=0;e<N;e++)
cs[e]=t[e];
do{
if(cs[0]=='1')
xor();
for(c=0;c<N-1;c++)
cs[c]=cs[c+1];
cs[c]=t[e++];
}while(e<=a+N-1);
}
int main()
{
printf("\nEnter data : ");
scanf("%s",t);
printf("\n ----- ");
printf("\nGeneratng polynomial : %s",g);
a=strlen(t);
for(e=a;e<a+N-1;e++)
t[e]='0';
printf("\n ----- ");
printf("\nModified data is : %s",t);
printf("\n ----- ");
crc();
printf("\nChecksum is : %s",cs);
for(e=a;e<a+N-1;e++)
t[e]=cs[e-a];
printf("\n ----- ");
printf("\nFinal codeword is : %s",t);
printf("\n ----- ");
printf("\nTest error detection 0(yes) 1(no)? : ");
scanf("%d",&e);
if(e==0)
{
do{
printf("\nEnter the position where error is to be inserted : ");
scanf("%d",&e);
}while(e==0 || e>a+N-1);
t[e-1]=(t[e-1]=='0')?'1':'0';
printf("\n ----- ");
printf("\nErroneous data : %s\n",t);
}
crc();
for(e=0;(e<N-1) && (cs[e]!='1');e++);
if(e<N-1)
printf("\nError detected\n\n");
else
printf("\nNo error detected\n\n");
printf("\n ----- \n");
return 0;
}
OUTPUT:
----------------------------------------
Generatng polynomial : 1011
----------------------------------------
Modified data is : 10100001000
----------------------------------------
Checksum is : 010
----------------------------------------
Final codeword is : 10100001010
----------------------------------------
Test error detection 0(yes) 1(no)? : no
No error detected
----------------------------------------
--------------------------------
Process exited after 60.61 seconds with return value 0
Press any key to continue . . .