19mis0018 CN Lab 2
19mis0018 CN Lab 2
19mis0018 CN Lab 2
DIGITAL ASSIGNMENT-2
Name : ESWAR G
Reg.No: 19MIS0018
Course Code : SWE2002
Faculty : Dr.C.NAVANEETHAN
Slot : VL2020210503313
1. Write a program to display the name and IP address of device that you
are currently working on.
CODE :
import java.net.*;
import java.io.*;
import java.util.*;
import java.net.InetAddress;
(localhost.getHostAddress()).trim());
}}
OUTPUT:
CODE:
import java.net.InetAddress;
import java.net.UnknownHostException;
public class IpAdd{
UnknownHostException {
System.out.println(InetAddress.getByName("www.vit.ac.in"));
System.out.println(InetAddress.getByName("www.google.com"));
InetAddress[] inetAddresses
=InetAddress.getAllByName("www.microsoft.com");
System.out.println(ipAddress);
break;
}}}
OUTPUT:
CODE:
import java.io.*;
import java.net.*;
import java.util.*;
NetworkInterface.getNetworkInterfaces();
displayInterfaceInformation(netint);
System.out.println("\n");
}}
OUTPUT:
import java.net.*;
import java.util.*;
while(interfaces.hasMoreElements() )
{NetworkInterface ni=(NetworkInterface)interfaces.nextElement();
System.out.println(ni.getIndex());
System.out.println("Display name:"+ni.getDisplayName());
System.out.println("Name:"+ni.getName());
byte[] hwaddr=ni.getHardwareAddress();
Enumeration addresses=ni.getInetAddresses();
while(addresses.hasMoreElements())
{ System.out.println(addresses.nextElement());
}} } }
4. Write a program to implement the “nslookup” utility.
CODE:
import java.net.InetAddress;
import java.net.UnknownHostException;
}}}
OUTPUT:
CODE:
import java.net.*;
import java.util.*;
class Url{
try{
URL aurl=new
URL("https://www.codejava.net/java-
se/networking/usehttpurlconnection-to-download-file-from-an-http-url");
System.out.println("Protocol= "+aurl.getProtocol());
System.out.println("Authority= "+aurl.getAuthority());
System.out.println("Host= "+aurl.getHost());
System.out.println("Port= "+aurl.getPort());System.out.println("path=
"+aurl.getPath());
System.out.println("Query= "+aurl.getQuery());
System.out.println("Filename= "+aurl.getFile());
System.out.println("Ref= "+aurl.getRef());
}catch(Exception e){
e.printStackTrace();
}}}
OUTPUT:
CODE:
import java.lang.*;
class Traceroute{
BufferedReader in;
try{
Runtime r = Runtime.getRuntime();
String line;
if(p==null)
while((line=in.readLine())!=null){
System.out.println(line);
}catch(IOException e){
System.out.println(e.toString());
}}}
OUTPUT:
7. Write a Program to illustrate the loopback address for testing TCP/IP
configuration.
CODE:
import java.net.InetAddress;
}}
OUTPUT:
8. Write a program to display IP address of host and local host with cache
tables for all interfaces.
CODE:
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;import
java.net.UnknownHostException;
import java.util.Collections;
import java.util.Enumeration;
try {
InetAddress ipaddress = InetAddress.getLocalHost();
ipaddress.getHostName());
ipaddress.getHostAddress());
Enumeration<NetworkInterface> interfaces =
NetworkInterface.getNetworkInterfaces();
System.out.println();
System.out.println();
if (interfaces == null) {
else {
}}
catch (SocketException e) {
}}}
OUTPUT:
9. Write a program to display active TCP Connections and illustrate the
possible state of TCP Connection.
CODE:
import java.io.*;
import java.net.*;
class TCPClients {
String modifiedSentence;
InputStreamReader(System.in));
DataOutputStream outToServer =
InputStreamReader(clientSocket.getInputStream()));
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence);
modifiedSentence = inFromServer.readLine();
clientSocket.close();
}
OUTPUT:
10.Explain the protocols TCP, UDP, ICMP, and IP Protocols. Illustrate
TCP, UDP, ICMP for IPv6 protocol. Identify the command that can be
used to specify a set of protocols.
ANSWER:
Internet Protocol (IP) – a set of rules that dictate how data should be delivered
over the public network (Internet). Often works in conjunction with the
transmission control protocol (TCP), which divides traffic into packets for
efficient transport through the Internet; together they are referred to as TCP/IP.
Netstat [-a] [-b] [-e] [-n] [-0] [-p <Protocol>] [-r] [-s]