Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Experiment 1 : Networking Commands

1. ping: Used to test the reachability of a host on an Internet Protocol (IP) network. It sends ICMP echo
request packets to the target host and waits for an ICMP echo reply.

2. traceroute (or tracert on Windows): Traces the route that packets take to reach a destination host. It
shows the IP addresses of the routers along the path and measures the time it takes for packets to reach
each router.

3. ifconfig (or ipconfig on Windows): Displays the configuration of all network interfaces on the system
including IP addresses, MAC addresses, and network-related statistics.

4. netstat: Displays network connections, routing tables, interface statistics, masquerade connections,
and multicast memberships.

5. nslookup (or dig): Used to query the Domain Name System (DNS) to obtain domain name or IP
address mapping, or other DNS records.

6. route: Displays or modifies the computer's routing table. It shows the IP routing table and allows users
to manipulate routing entries.

7. arp: Displays and modifies the Address Resolution Protocol (ARP) cache, which contains mappings of
IP addresses to MAC addresses.

8. ssh: Stands for Secure Shell. It is used to securely access a remote computer or server over a network.
It provides encrypted communication between the client and the server.

9. scp: Stands for Secure Copy Protocol. It is used to securely copy files between hosts on a network. It
uses SSH for data transfer and provides encryption and authentication.

10. wget (or curl): Used to download files from the web. It retrieves content from web servers using
HTTP, HTTPS, or FTP protocols.
Experiment 2 : WireShark

WireShark Interface

UDP
TCP

TLS
Failure
Experiment 3 : Client Server Architecture
Code:
Server :
import java.io.*;

import java.net.*;

public class server {

public static void main(String[] args) {

int portNumber = 8080;

try (

ServerSocket serverSocket = new ServerSocket(portNumber);

Socket clientSocket = serverSocket.accept();

PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);

BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

){

System.out.println("Server is listening on port " + portNumber + "...");

System.out.println("Client connected from: " + clientSocket.getInetAddress().getHostAddress());

String inputLine;

while ((inputLine = in.readLine()) != null) {

System.out.println("Received from client: " + inputLine);

out.println(inputLine);

} catch (IOException e) {

System.out.println("Exception caught when trying to listen on port " + portNumber + " or listening for a
connection");

System.out.println(e.getMessage());
}

Client :

import java.io.*;

import java.net.*;

public class client {

public static void main(String[] args) {

String hostName = "127.0.0.1";

int portNumber = 8080;

try (

Socket socket = new Socket(hostName, portNumber);

PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in))

){

System.out.println("Connected to server");

String userInput;

while ((userInput = stdIn.readLine()) != null) {

out.println(userInput);

System.out.println("Received from server: " + in.readLine());

if (userInput.equals("quit")) {

break;
}

} catch (UnknownHostException e) {

System.err.println("Don't know about host " + hostName);

System.exit(1);

} catch (IOException e) {

System.err.println("Couldn't get I/O for the connection to " + hostName);

System.exit(1);

Output:
Experiment 4 : Multithreaded Socket Programming
Code:
Server :
import java.io.*;

import java.net.*;

public class multiThreadServer {

public static void main(String[] args) {

int portNumber = 8050;

try (ServerSocket serverSocket = new ServerSocket(portNumber)) {

System.out.println("Server is listening on port " + portNumber + "...");

while (true) {

Socket clientSocket = serverSocket.accept();

System.out.println("New client connected: " + clientSocket.getInetAddress().getHostAddress());

ClientHandler clientHandler = new ClientHandler(clientSocket);

Thread clientThread = new Thread(clientHandler);

clientThread.start();

} catch (IOException e) {

System.out.println("Exception caught when trying to listen on port " + portNumber + " or listening for a
connection");

System.out.println(e.getMessage());
}

class ClientHandler implements Runnable {

private Socket clientSocket;

public ClientHandler(Socket clientSocket) {

this.clientSocket = clientSocket;

public void run() {

try (

PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);

BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

){

String inputLine;

while ((inputLine = in.readLine()) != null) {

System.out.println("Received from client " + clientSocket.getInetAddress().getHostAddress() + ": " +


inputLine);

out.println(inputLine);

} catch (IOException e) {

System.out.println("Exception caught when trying to read/write from/to client");

System.out.println(e.getMessage());

} finally {

try {

clientSocket.close();
} catch (IOException e) {

System.out.println("Exception caught when trying to close client socket");

System.out.println(e.getMessage());

Client :

import java.io.*;

import java.net.*;

public class multiThreadClient {

public static void main(String[] args) {

String hostName = "127.0.0.1";

int portNumber = 8050;

try (

Socket socket = new Socket(hostName, portNumber);

PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in))

){

System.out.println("Connected to server");

String userInput;

while ((userInput = stdIn.readLine()) != null) {


out.println(userInput);

System.out.println("Received from server: " + in.readLine());

if (userInput.equals("quit")) {

break;

} catch (UnknownHostException e) {

System.err.println("Don't know about host " + hostName);

System.exit(1);

} catch (IOException e) {

System.err.println("Couldn't get I/O for the connection to " + hostName);

System.exit(1);

Output:

You might also like