import java.io.*; import java.net.*; public class udpdnsserver { private static int indexOf(String[] array, String str) { //eliminate leading and trailing spaces str = str.trim(); for (int i=0; i < array.length; i++) { if (array[i].equals(str)) return i; } return -1; } public static void main(String arg[])throws IOException { //declare host names in an array String[] hosts = {"yahoo.com", "gmail.com","cricinfo.com", "facebook.com"}; //declare IP address in an array String[] ip = {"68.180.206.184", "209.85.148.19","80.168.92.140", "69.63.189.16"}; System.out.println("Press Ctrl + C to Quit");
while (true) { //create the Serversocket for to listen at port 1362 DatagramSocket serversocket=new DatagramSocket(1362); //declare byte level array for send/recieve data byte[] senddata = new byte[1021]; byte[] receivedata = new byte[1021]; //create object for recievepacket //returns the data,length of data DatagramPacket recvpack = new DatagramPacket(receivedata,receivedata.length); //recieve data from recvpocket serversocket.receive(recvpack); //getting host name String sen = new String(recvpack.getData()); //getting IP Address InetAddress ipaddress = recvpack.getAddress(); //getting port address int port = recvpack.getPort(); String capsent; System.out.println("Request for host " + sen); //check wether the Host present or not if(indexOf (hosts, sen) != -1) //if host present get IP address capsent = ip[indexOf (hosts, sen)]; else capsent = "Host Not Found"; //encode the String to bytes and return array of bytes senddata = capsent.getBytes(); //create a pack packet to sent data to client DatagramPacket pack = new DatagramPacket (senddata, senddata.length,ipaddress,port); //sent the packet serversocket.send(pack); //close the socket serversocket.close(); } } } UDP DNS Client : Udpdnsclient.java //import necessary packages import java.io.*; import java.net.*; public class udpdnsclient
{ public static void main(String args[])throws IOException { //create buffer reader to reads text from input stream BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //create a client socket DatagramSocket clientsocket = new DatagramSocket(); InetAddress ipaddress; if (args.length == 0) //get localhost address ipaddress =InetAddress.getLocalHost(); else //getting IP address ipaddress = InetAddress.getByName(args[0]); //declare byte level array for send/recieve data byte[] senddata = new byte[1024]; byte[] receivedata = new byte[1024]; //decler client’s port address int portaddr = 1362; System.out.print("Enter the hostname : "); //get hostname String sentence = br.readLine(); //encode the String to bytes and return array of bytes senddata = sentence.getBytes(); //create a pack packet to request data to the server DatagramPacket pack = new DatagramPacket(senddata,senddata.length, ipaddress,portaddr); //send the request to server clientsocket.send(pack); //create packet to to recieve data from server DatagramPacket recvpack =new DatagramPacket(receivedata,receivedata.length); //recieve data from server clientsocket.receive(recvpack); //print the values String modified = new String(recvpack.getData()); System.out.println("IP Address: " + modified); //close the client socket clientsocket.close(); } }
import java.util.*; //Header to import the required modules public class CRC { public static void main(String args[]) { Scanner sc=new Scanner(System.in); //Scanner is used to get a value from user,sc means object instead //of sc and name can be used as a object int m,g[],n,d[],z[],r[],msb,i,j,k; //declare the requried variable System.out.print ("Enter no. of data bits : "); // System.out.print is used to print the statement n=sc.nextInt(); //get the value for no of bits System.out.print("Enter no. of generator bits : "); m=sc.nextInt(); //get the value for no of generator bits d=new int[n+m]; //INITIALIZE THE ARRAY AND SIZE IS SUM OF DATA AND GENERATOR BIT g=new int[m]; //Initialize the array and size is no of generator bit System.out.print("Enter data bits : "); for(i=0;i<n;i++) d[i]=sc.nextInt(); System.out.print("Enter generator bits : "); for(j=0;j<m;j++) g[j]=sc.nextInt(); for(i=0;i<m-1;i++) d[n+i]=0; r=new int[m+n]; for(i=0;i<m;i++) r[i]=d[i]; z=new int[m];
import java.io.*; //add all the classes and interface which are already defined in io package import java.net.*; //package is used for network things related programming class Clientarp { public static void main(String args[]) { try { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); try (Socket clsct = new Socket("127.0.0.1",139)) { DataInputStream din=new DataInputStream(clsct.getInputStream()); DataOutputStream dout=new DataOutputStream(clsct.getOutputStream()); System.out.println("Enter the Logical address(IP):");
import java.awt.image.*;
ReplyDeleteimport javax.imageio.*;
import java.io.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException; import
javax.imageio.ImageIO;
public class Client{
public static void main(String args[]) throws Exception{
Socket soc;
BufferedImage img = null;
soc=new Socket("localhost",4000);
System.out.println("Client is running. ");
try {
System.out.println("Reading image from disk. ");
img = ImageIO.read(new File("image.jpg"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
baos.flush();
byte[] bytes = baos.toByteArray();
baos.close();
System.out.println("Sending image to server. ");
OutputStream out = soc.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
dos.writeInt(bytes.length);
dos.write(bytes, 0, bytes.length);
System.out.println("Image sent to server. ");
dos.close();
out.close();
}catch (Exception e) { System.out.println("Exception: " + e.getMessage());
soc.close();
}
soc.close();
}
}
Server.java
import java.net.*;
import java.io.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
class Server {
public static void main(String args[]) throws Exception{
ServerSocket server=null;
Socket socket;
server=new ServerSocket(4000);
System.out.println("Server Waiting for image");
socket=server.accept(); System.out.println("Client connected.");
InputStream in = socket.getInputStream();
DataInputStream dis = new DataInputStream(in);
int len = dis.readInt();
System.out.println("Image Size: " + len/1024 + "KB"); byte[] data = new byte[len];
dis.readFully(data);
dis.close();
in.close();
InputStream ian = new ByteArrayInputStream(data);
BufferedImage bImage = ImageIO.read(ian);
JFrame f = new JFrame("Server");
ImageIcon icon = new ImageIcon(bImage);
JLabel l = new JLabel();
l.setIcon(icon);
f.add(l);
f.pack();
f.setVisible(true);
}
}
// Import required java libraries
ReplyDeleteimport java.io.*;
import javax.servlet.*;
import javax.servlet.htp.*;
// Extend HttServlet class
public class HelloForm extends HttServlet {
public void doGet(HttServletRequest request, HttServletResponse response)
throws ServletException, IOException {
// Set response content type
response.setContentType("text/htm");
PrintWriter out = response.getWriter();
String tite = "Using GET Method to Read Form Data";
String docType =
"\n";
out.println(docType +
"\n" +
"" + titl+ "\n" +
"\n" +
"" + titl + "\n" +
"\n" +
" First Name: "
+ request.getParameter("first_name") + "\n" +
" Last Name: "
+ request.getParameter("last_name") + "\n" +
"\n" +
"" +
""
);
}
}
ReplyDeleteTesting
TestingServlet
Testing
/welcome
import java.io.*;
ReplyDeleteimport java.net.*;
public class udpdnsserver
{
private static int indexOf(String[] array, String str)
{
//eliminate leading and trailing spaces
str = str.trim();
for (int i=0; i < array.length; i++)
{
if (array[i].equals(str))
return i;
}
return -1;
}
public static void main(String arg[])throws IOException
{
//declare host names in an array
String[] hosts = {"yahoo.com", "gmail.com","cricinfo.com", "facebook.com"};
//declare IP address in an array
String[] ip = {"68.180.206.184", "209.85.148.19","80.168.92.140", "69.63.189.16"};
System.out.println("Press Ctrl + C to Quit");
while (true)
ReplyDelete{
//create the Serversocket for to listen at port 1362
DatagramSocket serversocket=new DatagramSocket(1362);
//declare byte level array for send/recieve data
byte[] senddata = new byte[1021];
byte[] receivedata = new byte[1021];
//create object for recievepacket //returns the data,length of data
DatagramPacket recvpack = new DatagramPacket(receivedata,receivedata.length);
//recieve data from recvpocket
serversocket.receive(recvpack);
//getting host name
String sen = new String(recvpack.getData());
//getting IP Address
InetAddress ipaddress = recvpack.getAddress();
//getting port address
int port = recvpack.getPort();
String capsent;
System.out.println("Request for host " + sen);
//check wether the Host present or not
if(indexOf (hosts, sen) != -1)
//if host present get IP address
capsent = ip[indexOf (hosts, sen)];
else capsent = "Host Not Found";
//encode the String to bytes and return array of bytes
senddata = capsent.getBytes();
//create a pack packet to sent data to client
DatagramPacket pack = new DatagramPacket (senddata, senddata.length,ipaddress,port);
//sent the packet
serversocket.send(pack);
//close the socket
serversocket.close();
}
}
}
UDP DNS Client :
Udpdnsclient.java
//import necessary packages
import java.io.*;
import java.net.*;
public class udpdnsclient
{
ReplyDeletepublic static void main(String args[])throws IOException
{
//create buffer reader to reads text from input stream
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//create a client socket
DatagramSocket clientsocket = new DatagramSocket();
InetAddress ipaddress;
if (args.length == 0)
//get localhost address
ipaddress =InetAddress.getLocalHost();
else
//getting IP address
ipaddress = InetAddress.getByName(args[0]);
//declare byte level array for send/recieve data
byte[] senddata = new byte[1024];
byte[] receivedata = new byte[1024];
//decler client’s port address
int portaddr = 1362;
System.out.print("Enter the hostname : ");
//get hostname
String sentence = br.readLine();
//encode the String to bytes and return array of bytes
senddata = sentence.getBytes();
//create a pack packet to request data to the server
DatagramPacket pack = new DatagramPacket(senddata,senddata.length, ipaddress,portaddr);
//send the request to server
clientsocket.send(pack);
//create packet to to recieve data from server
DatagramPacket recvpack =new DatagramPacket(receivedata,receivedata.length);
//recieve data from server
clientsocket.receive(recvpack);
//print the values
String modified = new String(recvpack.getData());
System.out.println("IP Address: " + modified);
//close the client socket
clientsocket.close();
}
}
import java.util.*; //Header to import the required modules
ReplyDeletepublic class CRC
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in); //Scanner is used to get a value from user,sc means object
instead //of sc and name can be used as a object
int m,g[],n,d[],z[],r[],msb,i,j,k; //declare the requried variable
System.out.print ("Enter no. of data bits : "); // System.out.print is used to print the statement
n=sc.nextInt(); //get the value for no of bits
System.out.print("Enter no. of generator bits : ");
m=sc.nextInt(); //get the value for no of generator bits
d=new int[n+m]; //INITIALIZE THE ARRAY AND SIZE IS SUM OF DATA AND
GENERATOR BIT
g=new int[m]; //Initialize the array and size is no of generator bit
System.out.print("Enter data bits : ");
for(i=0;i<n;i++)
d[i]=sc.nextInt();
System.out.print("Enter generator bits : ");
for(j=0;j<m;j++)
g[j]=sc.nextInt();
for(i=0;i<m-1;i++)
d[n+i]=0;
r=new int[m+n];
for(i=0;i<m;i++)
r[i]=d[i];
z=new int[m];
for(i=0;i<m;i++)
ReplyDeletez[i]=0;
for(i=0;i<n;i++)
{
k=0;
msb=r[i];
for(j=i;j<m+i;j++)
{
if(msb==0)
r[j]=xor(r[j],z[k]); //checks for XOR condition which is same means 1 different means 0
else
r[j]=xor(r[j],g[k]);
k++;
}
r[m+i]=d[m+i];
}
System.out.print("The code bits added are : ");
for(i=n;i<n+m-1;i++)
{
d[i]=r[i];
System.out.print(d[i]);
}
System.out.print("\nThe code data is : ");
for(i=0;i<n+m-1;i++)
{
System.out.print(d[i]);
}
}
public static int xor(int x,int y)
ReplyDelete{
if(x==y)
return(0);
else
return(1);
}
}
import java.io.*; //add all the classes and interface which are already defined in io package
ReplyDeleteimport java.net.*; //package is used for network things related programming
class Clientarp
{
public static void main(String args[])
{
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
try (Socket clsct = new Socket("127.0.0.1",139)) {
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
System.out.println("Enter the Logical address(IP):");
String str=in.readLine(); sendbyte=str.getBytes();
ReplyDeleteDatagramPacket sender=newDatagramPacket(sendbyte,sendbyte.length,addr,1309);
client.send(sender);
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData());
System.out.println("The Logical Address is(IP): "+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
import java.io.*;
ReplyDeleteimport java.net.*;
import java.util.*;
class Serverrarp12
{
public static void main(String args[])
{
try
{
DatagramSocket server=new DatagramSocket(1309);
while(true)
{
byte[] sendbyte=new byte[1024];
ReplyDeletebyte[] receivebyte=new byte[1024];
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
server.receive(receiver);
String str=new String(receiver.getData());
String s=str.trim();
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
String
ip[]={"165.165.80.80","165.165.79.1"};
String
mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<ip.length;i++)
{
if(s.equals(mac[i]))
{
sendbyte=ip[i].getBytes();
DatagramPacket sender=newDatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
}
break;
}
}
catch(Exception e)
{
System.out.println(e);
https://drive.google.com/file/d/16D0vt6NpX7MlUrHLFcB87SL3PuECDRfK/view?usp=drivesdk
ReplyDeletehttps://drive.google.com/file/d/1R7gyX0l7P_gFhIiSbrsdsEU33O7dLFaA/view?usp=drivesdk
ReplyDeleteHi
ReplyDeletehttps://drive.google.com/file/d/1cHrykg3-IbOP1GV9xRv27I_XV3GijxkO/view?usp=drivesdk
ReplyDeletehttps://drive.google.com/file/d/1JdxTx5rkL3DJuxPFTAz79g2yKpX4fFT0/view?usp=drivesdk
ReplyDeleteReenu
kad
Shankar
85
Vaneet
narayanan
vini
95
janavi
raju
janu
93
https://drive.google.com/file/d/1L6g1kI_51J3vDfqT51WVcDBTSSUI_zPx/view?usp=drivesdk
ReplyDeletehttps://docs.google.com/document/d/1YbCtxwEY0pl4Yh9g7F6Uj3LanCe0ZQVy/edit?usp=drivesdk&ouid=113721818669334980887&rtpof=true&sd=true
ReplyDeletehttps://drive.google.com/file/d/1lz5rbfEVEv4EF_sT8r1WLzszb4Wn_wl4/view?usp=drivesdk
ReplyDelete