FORM NO.
- F/ TL / 021
Rev.00 Date 20.03.2020
RECORD NOTEBOOK
BCS18L05 – NETWORK PROGRAMMING LAB
2023–2024 (ODD SEMESTER)
DEPARTMENT
OF
COMPUTER SCIENCE AND ENGINEERING
NAME : J.AMIRTHA HARSHINI
REGISTER NO : 221061101014
COURSE : B.TECH (CSE)
YEAR/SEM/SEC : III / V/ A
FORM NO.- F/ TL / 021
Rev.00 Date 20.03.2020
BONAFIDE CERTIFICATE
Register No: 221061101014
Name of Lab: NETWORK PROGRAMMING LAB
Department: COMPUTER SCIENCE AND ENGINEERING
Certified that, this Record note book is a bonafide record of work done by
J.AMIRTHA HARSHINI of III Year B. Tech / CSE, Sec - ‘A’ in the NETWORK
PROGRAMMING LAB during the year 2023-2024.
Signature of Lab-in-Charge Signature of Head of Dept
Submitted for the Practical Examination held on
Internal Examiner External Examiner
INDEX
Exp Staff
Date Name Of Experiment Page No
No Signature
1 24/07/2024 Networking Commands With Options
Socket Program To Extent Communication Between
2 24/07/2024
Two Different Ends Using TCP.
Socket program to extent communication
3 27/07/2024
between two different ends using UDP.
Create a Socket (TCP) between two computers
4 27/07/2024
and enable file transfer between them.
5 31/07/2024 Implementation of RPC in server-client model
6 21/08/2024 Implementation of ARP/RARP
7 28/08/2024 HTTP Socket program to download a webpage
File transfer in Client-Server architecture using
8 11/09/2024
following methods using RS232C.
9 11/09/2024 To implement RMI (Remote Method Invocation)
10 18/09/2024 Implementing the demonstration of network
simulators.
PROGRAM
1. PING
This is used to provide a basic connectivity test between the requesting host and destination
host.
2. IPCONFIG:
This command will display basic details about the devices IP address configuration.
3. TRACERT
It is used to get the network packet being sent and received and the number of hops required
for that packet to reach to target.
4. ROUTE
It displays all the different fields in the active route.
5. NBTSTAT
Its primary design is to help troubleshoot NetBIOS name resolution
6. ARP
It stands for address resolution protocol. Used to display and modify entries in address
resolution protocol cache
7. HOSTNAME
Host name this is used to return local computer name.
8. GETMAC
Getmac used to show both local and mac address.
9. NSLOOKUP
Nslookup this utility used to lookup specific ip address associated with domain name.
10. NETSTAT
Netstat this is used to figure out correct state of active network connection on a host.
11. FINGER
Finger this enables a user to view other user information when user in the same system.
12. PATHPING
Pathping it take the functionality and information that can be obtained from this type of tools
provides information about network latency and network loss of intermediate hops between a
source and destination.
TELNET
This is a software that allow user to remotely access another computer such as server etc.
OUTPUT
NETSH
Netsh used to display protocol statistics and current tcp/ip connection using nbt.
OUTPUT
IPCONFIG/FLUSHDNS
Ipconfig/flushdns it displays all current TCP/IP network configuration values and reference DHCP.
OUTPUT
NET
Net used to create, remove and otherwise manage shared resource so n system.
OUTPUT
CIPHER
Cipher this is a built-in command line tool in OS used to encrypt or decrypt data on ntfs drives.
OUTPUT
PROGRAM
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("\
nDHANANJAY YADAV – 211061101099 \n");
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);
}
}
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"); System.out.println("\AMIRTHA
HARSHINI -221061101014\n"); 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.clos
e();
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
PROGRAM
SERVER
import java.io.IOException;
import java.net.
DatagramPacket; import
java.net.DatagramSocket; import
java.net.InetAddress; import
java.net.SocketException; public
class udpBaseServer{
public static void main(String[] args) throws IOException{
System.out.println("\NAMIRTHA HARSHINI - 221061101014\n");
DatagramSocket ds = new DatagramSocket(1234);
byte[] receive = new byte[65535];
DatagramPacket DpReceive = null;
while (true){
DpReceive = new DatagramPacket(receive, receive.length);
ds.receive(DpReceive);
System.out.println("Client:-" + data(receive));
if(data(receive).toString().equals("bye")){
System.out.println("Client sent by..EXITING");
break;
}
receive = new byte[65535];
}
}
public static StringBuilder data(byte[]a){
if (a == null)
return null;
StringBuilder ret = new StringBuilder();
int i= 0;
while (a[i] !=0){
ret.append((char) a[i]);
i++;
}
return ret;
}
}
CLIENT
import java.io.IOException;
import java.net.DatagramPacket;
import java.net. DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;
public class udpBaseClient{
public static void main(String args[]) throws IOException{
System.out.println("\AMIRTHA HARSHINI -221061101014\n");
Scanner sc = new Scanner(System.in);
DatagramSocket ds = new
DatagramSocket(); InetAddress ip =
InetAddress.getLocalHost(); byte buf[]=null;
while (true){
String inp = sc.nextLine();
buf=inp.getBytes();
DatagramPacket DpSend =new DatagramPacket(buf, buf.length, ip, 1234);
ds.send(DpSend);
if (inp.equals("bye"))
break;
}
}
}
OUTPUT
PROGRAM
SERVER
import java.io.*;
import java.net.*;
class Cyber4{
public static void main(String args[]) throws IOException{
System.out.println("\AMIRTHA HARSHINI -221061101014\n");
ServerSocket ss=new ServerSocket(7777);
Socket s=ss.accept();
System.out.println("connected...");
FileInputStream fin=new FileInputStream("C:\\Users\\yadav\\Desktop\\NP\\send.txt");
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
int r; while((r=fin.read())!
=-1){ dout.write(r);
}
System.out.println("\nFile transfer completed");
s.close();
ss.close();
}
}
CLIENT
import java.io.*;
import java.net.*;
class Student4{
public static void main(String args[]) throws IOException{
System.out.println("\AMIRTHA HARSHINI -221061101014\n");
Socket s=new Socket("127.0.0.1",7777);
if(s.isConnected()){
System.out.println("connected to server");
}
FileOutputStream fout = new FileOutputStream("C:\\Users\\
yadav\\Desktop\\NP\\received.txt"); DataInputStream din = new
DataInputStream(s.getInputStream()); int r;
while((r=din.read())!=-1){
fout.write((char)r);
}
s.close();
}
}
OUTPUT
PROGRAM
SERVER
import java.io.*;
import java.net.*;
class Server5{
public static void main(String[] args) throws Exception{
System.out.println("\AMIRTHA HARSHINI -221061101014\n");
ServerSocket sersock = new ServerSocket(3000);
System.out.println("Server ready");
Socket sock = sersock.accept();
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = sock.getInputStream();
BufferedReader receiveRead= new BufferedReader(new InputStreamReader(istream));
String receiveMessage, sendMessage, fun; int a, b, c;
while (true){
fun = receiveRead.readLine();
if(fun != null)
System.out.println("Operation :" + fun);
a= Integer.parseInt(receiveRead.readLine());
System.out.println("Parameter 1l:"+a);
b= Integer.parseInt(receiveRead.readLine());
if (fun.compareTo("add")==0){
c=a+b;
System.out.println("Addition ="+ c);
pwrite.println("Addition =" +c);
}
if (fun.compareTo("sub")==0){
c=a-b;
System.out.println("Substraction ="+ c);
pwrite.println("Substraction ="+c);
}
if(fun.compareTo("mul")==0){
c=a*b;
System.out.println("Multiplication ="+c);
pwrite.println("Multiplication ="+c);
}
if(fun.compareTo("div")==0){
c=a/b;
System.out.println("Division ="+ c);pwrite.println("Division ="+c);
}
System.out.flush();
}
}
}
CLIENT
import java.io.*;
import java.net.*;
class Client5{
public static void main(String[] args) throws Exception{
System.out.println("DHANANJAY YADAV - 211061101099\n");
Socket sock = new Socket("127.0.0.1", 3000);
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
System.out.println("Client ready,type and press Enter key");
String receiveMessage, sendMessage, temp;
while (true){
System.out.println("\nEnter operation to perform(add,sub,mul,div)...");
temp = keyRead.readLine();
sendMessage = temp.toLowerCase();
pwrite.println(sendMessage);
System.out.println("Enter first parameter :");
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
System.out.println("Enter second parameter :");
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
System.out.flush();
if((receiveMessage = receiveRead.readLine())!=null)
System.out.println(receiveMessage);
}
}
}
OUTPUT
PROGRAM
import java.io.*;
import java.util.*;
public class arp_rarp{
private static final String Command="arp -a";
public static void getARPTable(String cmd) throws Exception{
File fp=new File("ARPTable.txt");
FileWriter fw=new FileWriter(fp);
BufferedWriter bw=new BufferedWriter(fw);
Process P=Runtime.getRuntime().exec(cmd);
Scanner S=new Scanner(P.getInputStream()).useDelimiter("\\A");
while(S.hasNext()) bw.write(S.next()); bw.close();fw.close();
}
public static void findMAC(String ip) throws Exception{
File fp=new File("ARPTable.txt");
FileReader fr=new FileReader(fp);
BufferedReader br=new BufferedReader(fr); String line;
while((line=br.readLine())!=null){
if(line.contains(ip)){
System.out.println("Internet Address Physical Address Type");
System.out.println(line); break;
}}
if(line==null)
System.out.println("Not found"); fr.close(); br.close();
}
public static void findIP(String mac) throws Exception{
File fp=new File("ARPTable.txt");
FileReader fr=new FileReader(fp);
BufferedReader br=new BufferedReader(fr); String line;
while((line=br.readLine())!=null){ if(line.contains(mac))
{
System.out.println("Internet Address Physical Address Type");
System.out.println(line);
break;
}}
if(line==null)
System.out.println("Not Found"); fr.close(); br.close();
}
public static void main(String args[]) throws Exception{
System.out.println("\AMIRTHA HARSHINI -221061101014\n");
getARPTable(Command); Scanner S=new Scanner(System.in);
System.out.println("ARP Protocol");
String IP=S.nextLine(); findMAC(IP);
System.out.println("RARP Protocol"); System.out.print("Enter MAC Address:");
String MAC=S.nextLine(); findIP(MAC);
}
}
OUTPUT
PROGRAM
package normal;
import java.io.*;
import java.net.URL;
import java.net.MalformedURLException;
public class Main {
public static void DownloadWebPage(String webpage){
try{
URL url = new URL("http://www.google.com");
BufferedReader readr = new BufferedReader(new InputStreamReader(url.openStream()));
BufferedWriter writer = new BufferedWriter(new FileWriter("Data.html"));
String line;
while ((line = readr.readLine()) != null){
writer.write(line);
}
readr.close(); writer.close();
System.out.println("\AMIRTHA HARSHINI -221061101014\n");
System.out.println("Successfully Downloaded.");
}
catch (MalformedURLException mue){
System.out.println("Malformed URL Exception raised");
}
catch (IOException ie){
System.out.println("IOException raised");
}
}
public static void main(String args[])
throws IOException{
String url ="https://www.drmgrdu.ac.in/contact.php";
DownloadWebPage(url);
}
}
OUTPUT
PROGRAM
import java.io.*;
import javax.comm.*;
public class Rs232c {
public static void main(String args[]) {
try {
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("COM1");
SerialPort port = (SerialPort) portId.open("RS232C", 1000);
port.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
OutputStream out = port.getOutputStream();
String msg = "Transferred";
out.write(msg.getBytes());
out.flush();
out.close();
port.close();
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}
OUTPUT
.
PROGRAM
SERVER
import java.rmi.*;
import java.rmi.server.*;
Class RMIServer extends UnicastRemoteObject implements
Myinterface{ public RMIServer()throws RemoteException{
System.out.println("Remote Server is running Now.!!");
}
public static void main(String arg[]){ System.out.println("\
AMIRTHA HARSHINI -221061101014\n"); try{
RMIServer p=new RMIServer();
Naming.rebind("rmiInterface",p);
}
catch(Exception e){
System.out.println("Exception occurred: "+e.getMessage());
}
}
public String countInput(String input) throws RemoteException{
System.out.println("Received your input"+input+"at server!!");
String reply;
reply="You have typed"+input.length()+"letters!!";
return reply;
}
}
CLIENT
import java.rmi.*;
import java.io.*;
public class RMIClient{
public static void main(Stringargs[]){ System.out.println("\
AMIRTHA HARSHINI -221061101014\n"); try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Myinterface p=( myinterface)Naming.lookup("rmiInterface");
System.out.println("Type something...");
String input=br.readLine();
System.out.println(p.countInput(input));
}
catch(Exception e){
System.out.println("Exception occurred:"+e.getMessage());
}
}
}
MyInterface.java
import java.rmi.*;
public interface Myinterface extends Remote{
public String countInput(String input)throws RemoteException;
}
OUTPUT
PROGRAM
import java.net.*;
import java.io.*;
import java.util.*;
public class GroupChat{
private static final String TERMINATE = "Exit";
static String name;
static volatile boolean finished = false;
public static void main(String[] args){
System.out.println("AMIRTHA HARSHINI-221061101014\n");
if (args.length != 2)
System.out.println("Two arguments required: <multicast-host><port-number>");
else{
try{
InetAddress group = InetAddress.getByName(args[0]);
int port = Integer.parseInt(args[1]);
Scanner sc = new Scanner(System.in);
System.out.println("Enter your name:
"); name = sc.nextLine();
MulticastSocket socket = new MulticastSocket(port);
socket.setTimeToLive(0);
socket.joinGroup(group);
Thread t = new Thread(new
ReadThread(socket,group,port));
t.start();
System.out.println("Start typing messages...\n");
while(true){
String message;
message = sc.nextLine();
if(message.equalsIgnoreCase(GroupChat.TERMINATE))
{ finished = true;
socket.leaveGroup(group);
socket.close();
break;
}
message = name + ": " + message;
byte[] buffer =
message.getBytes();
DatagramPacket datagram = new
DatagramPacket(buffer,buffer.length,group,port);
socket.send(datagram);
}
}
catch(SocketException se){
System.out.println("Error creating
socket"); se.printStackTrace();
}
catch(IOException ie){
System.out.println("Error reading/writing from/to socket");
ie.printStackTrace();
}
}
}
}
class ReadThread implements Runnable{
private MulticastSocket socket;
private InetAddress group;
private int port;
private static final int MAX_LEN = 1000;
ReadThread(MulticastSocket socket,InetAddress group,int port){
this.socket = socket;
this.group = group;
this.port = port;
}
@Override
public void run(){ while(!
GroupChat.finished){
byte[] buffer = new
byte[ReadThread.MAX_LEN]; DatagramPacket
datagram = new
DatagramPacket(buffer,buffer.length,group,port);
String message;
try{ socket.receive(datagr
am); message = new
String(buffer,0,datagram.getLength(),"UTF-8"); if(!
message.startsWith(GroupChat.name)) System.out.println(message);
}
catch(IOException e){
System.out.println("Socket closed!");
}
}
}
}
OUTPUT