Sie sind auf Seite 1von 31

1.

Write socket programs to implement an echo server and a corresponding client (Both iterative and concurrent versions)

// ITERATIVE ECHO SERVER import java.net.*; import java.io.*; public class Echoserver { public static void main(String arr[]) throws Exception { System.out.println("Listening----"); ServerSocket ss=new ServerSocket(2000); Socket s=ss.accept(); InputStream is=s.getInputStream(); OutputStream os=s.getOutputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(is)); System.out.println("Printed on server"); String str=br.readLine(); System.out.println(str); PrintStream ps=new PrintStream(os); ps.println(str); s.close(); ss.close(); } }

// CONCURRENT ECHO SERVER import java.net.*; import java.io.*; class EchoCserver implements Runnable { Thread t; Socket s; EchoCserver(Socket s) { this.s=s; t=new Thread(this); t.start(); } public void run() { try { InputStream is=s.getInputStream(); OutputStream os=s.getOutputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(is)); String str=br.readLine(); System.out.println("Printed on server"); System.out.println(str); PrintStream ps=new PrintStream(os); ps.println(str);

s.close(); } catch (Exception ex) { System.out.println(ex); } }}

public class newThread { public static void main(String ar[]) { ServerSocket ss=null; try { ss=new ServerSocket(2000); System.out.println("Listening----"); } catch (Exception e) { System.out.println(e); } while(true) { try { Socket s =ss.accept();

new EchoCserver(s); } catch(Exception ex) { System.out.println(ex); } } } }

//ECHO CLIENT.... import java.net.*; import java.io.*; public class Echoclient { public static void main(String arr[]) throws Exception { Socket s=new Socket("127.0.0.1",2000); InputStream is=s.getInputStream(); OutputStream os=s.getOutputStream(); PrintStream ps=new PrintStream(os); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter text to echo--->"); String str=br.readLine(); ps.println(str); BufferedReader bb=new BufferedReader(new InputStreamReader(is)); System.out.println("Returned back to client----->"); String ss=bb.readLine(); System.out.println(ss); s.close(); } }

//Output1 // Iterative Server

E:\java>javac Echoserver.java

E:\java>java Echoserver Listening---Printed on server Anshul

E:\java>

//-Concurrent Server E:\java>javac newThread.java E:\java>java newThread Listening---Printed on server Anshul Chauhan

//-Echo Client

E:\java>javac Echoclient.java

E:\java>java Echoclient Enter text to echo---> Anshul Returned back to client-----> Anshul

E:\java>

2.Study of the following: ping, traceroute, nslookup, whois

NSLOOKUP: The name nslookup means name server lookup. Nslookup uses the operating system's local Domain Name System resolver library to perform its queries. Thus, it is configured automatically by the contents of the operating system file resolv.conf.nslookup operates in interactive or non-interactive mode. When used interactively, when the program is invoked without arguments (another option exists), the user issues parameter configurations or requests when presented the nslookup prompt ('>') in line by line fashion. In non-interactive mode parameters and the query are specified as command line arguments in the invocation of the program.

The general command syntax is: nslookup [-option] [name | -] [server]

The following example queries the Domain Name System for the IP address of the domain name example.com by issuing the command nslookup example.com to the command line interpreter (shell): $ nslookup example.com Server: Address: 192.168.0.254 192.168.0.254#53

Non-authoritative answer: Name: example.com Address: 192.0.32.10

-----------------------------------------------------------------------------------------

PING: Ping is a computer network administration utility used to test the reachability of a host on an Internet Protocol (IP) network and to measure the round-trip time for messages sent from the originating host to a destination computer. The name comes from active sonar terminology. Ping operates by sending Internet Control Message Protocol (ICMP) echo request packets to the target host and waiting for an ICMP response. In the process it measures the time from transmission to reception (round-trip time)[1] and records any packet loss. The results of the test are printed in the form of a statistical summary of the response packets received, including the minimum, maximum, and the mean round-trip times, and sometimes the standard deviation of the mean. Ping may be run using various options (command line switches) depending on the implementation that enable special operational modes, such as to specify the packet size used as the probe, automatic repeated operation for sending a specified count of probes, and time stamping options. # ping -c 5 www.example.com PING www.example.com (192.0.43.10) 56(84) bytes of data. 64 bytes from 43-10.any.icann.org (192.0.43.10): icmp_seq=1 ttl=250 time=80.5 ms 64 bytes from 43-10.any.icann.org (192.0.43.10): icmp_seq=2 ttl=250 time=80.4 ms 64 bytes from 43-10.any.icann.org (192.0.43.10): icmp_seq=3 ttl=250 time=80.3 ms 64 bytes from 43-10.any.icann.org (192.0.43.10): icmp_seq=4 ttl=250 time=80.3 ms 64 bytes from 43-10.any.icann.org (192.0.43.10): icmp_seq=5 ttl=250 time=80.4 ms

----------------------------------------------------------------------------------------

TRACEROUTE: traceroute is a computer network diagnostic tool for displaying the route (path) and measuring transit delays of packets across an Internet Protocol (IP) network. traceroute outputs the list of traversed routers in simple text format, together with timing information Traceroute is available on most operating systems. Traceroute sends a sequence of Internet Control Message Protocol (ICMP) echo request packets addressed to a destination host. Determining the intermediate routers traversed involves adjusting the time-to-live (TTL) aka hop limit Internet Protocol parameter. Frequently starting with a value like 128 (Windows) or 64 (Linux), routers decrement this and discard a packet when the TTL value has reached zero, returning the ICMP error message ICMP Time Exceeded. Traceroute works by increasing the TTL value of each successive set of packets sent. The first set of packets sent have a hop limit value of 1, expecting that they are not forwarded by the first router. The next set have a hop limit value of 2, so that the second router will send the error reply. This continues until the destination host receives the packets and returns an ICMP Echo Reply message. WHO IS: The WHOIS system originated as a method for system administrators to obtain contact information for IP address assignments or domain name administrators. The use of the data in the WHOIS system has evolved into a variety of uses, including:[citation needed] * Supporting the security and stability of the Internet by providing contact points for network operators and administrators, including ISPs, and certified computer incident response teams; * Determining the registration status of domain names; * Assisting law enforcement authorities in investigations for enforcing national and international laws, including. In some countries, specialized non-governmental entities may be involved in this work;[original research?] * Assisting in combating abusive uses of information communication technology;[2] * Facilitating inquiries and subsequent steps to conduct trademark research and to help counter intellectual property infringement;[citation needed] * Contributing to user confidence in the Internet as a reliable and efficient means of information and communication and as an important tool for promoting digital inclusion, e-commerce and other legitimate uses by helping users identify persons or entities responsible for content and services online; and * Assisting businesses, other organizations and users in combating fraud, complying with relevant laws and safeguarding the interests of the public.[dubious discuss]

3.Sending HTTP commands over telnet


BEFORE DOING THIS MAKE SURE THAT TELNET SERVICE ARE ACTIVATED 1. $ telnet microsoft.com 80 Trying 207.46.232.182... Connected to microsoft.com. Escape character is '^]'. HEAD / HTTP/1.0

HTTP/1.1 301 Moved Permanently Connection: close Date: Thu, 12 Jul 2007 15:25:37 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET Location: http://www.microsoft.com Content-Length: 31 Content-Type: text/html Set-Cookie: ASPSESSIONIDSCAQCSBR=FMPJMMPAMGNBFELIPABIHHMN; path=/ Cache-control: private

2. $ telnet tonycode.com 80 Trying 208.97.136.171... Connected to tonycode.com. Escape character is '^]'.

GET / HTTP/1.1 Host: tonycode.com

HTTP/1.1 200 OK Date: Thu, 12 Jul 2007 16:10:02 GMT Server: Apache/1.3.37 (Unix) mod_throttle/3.1.2 DAV/1.0.3 mod_fastcgi/2.4.2 mod_gzip/1.3.26.1a PHP/4.4.7 mod_ssl/2.8.22 OpenSSL/0.9.7e MS-Author-Via: DAV Last-Modified: Wed, 11 Jul 2007 14:10:28 GMT ETag: "19cf7aa-68d-4694e4d4" Accept-Ranges: bytes Content-Length: 1677 Content-Type: text/html

4.SMTP command sequence to verify whether an email address is valid or not?

Step 1. Enable telnet in Windows. Step 2. Open the command prompt and type the following command: nslookup type=mx gmail.com This command will extract and list the MX records of a domain as shown below. Replace gmail.com with the domain of the email address that you are trying to verify. gmail.com MX preference=30, exchanger = alt3.gmail-smtp-in.l.google.com gmail.com MX preference=20, exchanger = alt2.gmail-smtp-in.l.google.com gmail.com MX preference=5, exchanger = gmail-smtp-in.l.google.com gmail.com MX preference=10, exchanger = alt1.gmail-smtp-in.l.google.com gmail.com MX preference=40, exchanger = alt4.gmail-smtp-in.l.google.com

Step 3. As you may have noticed, it is not uncommon to have multiple MX records for a domain. Pick any one of the servers mentioned in the MX records, may be the one with the lowest preference level number (in our example, gmail-smtp-in.l.google.com), and pretend to send a test message to that server from you computer. For that, go to command prompt window and type the following commands in the listed sequence: 3a: Connect to the mail server: telnet gmail-smtp-in.l.google.com 25

3b: Say hello to the other server HELLO

3c: Identify yourself with some fictitious email address mail from:<labnol@labnol.org>

3d: Type the recipients email address that you are trying to verify: rcpt to:<billgates@gmail.com>

The server response for rcpt to command will give you an idea whether an email address is valid or not. Youll get an OK if the address exists else a 550 error like:

5.Studying IP datagram headers using Wireshark

Step 1: Review Transport layer operation. When PC_Client builds the datagram for a connection with eagle1.example.com, the datagram travels down the various network Layers. At each Layer, important header information is added. Because this communication is from a web client, the Transport Layer protocol will be TCP. Consider the TCP segment, shown in Figure 6. PC_Client generates an internal TCP port address, in this conversation 1085, and knows the well-known web server port address, 80. Likewise, a sequence number has been internally generated. Data is included, provided by the Application Layer. Some information will not be known to PC_Client, so it must be discovered using other network protocols. There is no acknowledgement number. Before this segment can move to the Network Layer, the

TCP threeway handshake must be performed. 16 TCP Segment Source Port Destination Port 0 31 Sequence Number Acknowledgement Number 47 Data Offset Reserved ECN 10 Control Bits Window

Checksum Urgent Pointer Options and Padding Data

TCP Segment fields. Step 2: Review Network layer operation. At the Network Layer, the IPv4 (IP) PACKET has several fields ready with information. This is shown in For example, the packet Version (IPv4) is known, as well as the source IP address. The destination for this packet is eagle1.example.com. The corresponding IP Address must be discovered through DNS (Domain Name Services). Until the upper layer datagram is received, fields related to the upper layer protocols are empty. 16 IP Packet Total Length 0 4 8 10 31 Source IP Address Version IHL TOS Identification Flags Fragment Offset Source IP Address TTL Data Protocol Header Checksum Destination IP Address Figure 7. IP Packet fields.

All contents are Copyright 19922007 Cisco Systems, Inc. All rights reserved. This document is Cisco Public Information. Page 4 of 9CCNA Exploration Network Fundamentals: Configuring and Testing Your Network Lab 11.5.6: Final Case Study - Datagram Analysis with Wireshark Step 3: Review Data Link layer operation. Before the datagram is placed on the physical medium, it must be encapsulated inside a frame. This is shown in Figure 8. PC_Client has knowledge of the source MAC address, but must discover the destination MAC address. The destination MAC address must be discovered. Preamble 8 Octets Destination Address 6 Octets Source Address 6 Octets Frame Type 2 Octets Data 46-1500 Octets CRC 4 Octets Ethernet II Frame Format

Figure 8. Ethernet II frame fields. Task 3: Analyze Captured Packets. Step 1: Review the data flow sequence. A review of missing information will be helpful in following the captured packet sequence: a. The TCP segment cannot be constructed because the acknowledgement field is blank. A TCP 3way handshake with eagle1.example.com must first be completed. b. The TCP 3-way handshake cannot occur because PC_Client does not know the IP address for eagle1.example.com. This is resolved with a DNS request from PC_Client to the DNS the server. c. The DNS server cannot be queried because the MAC address for the DNS server is not known. The ARP protocol is broadcast on the LAN to discover the MAC address for the DNS server. d. The MAC address for eagle1.example.com is unknown. The ARP protocol is broadcast on the LAN to learn the destination MAC address for eagle1.example.com.

6.Detailed Study of the IPCONFIG, NETSTAT and NETSH command

NETSTAT COMMAND Displays protocol statistics and current TCP/IP network connections. SYNTAX: NETSTAT [-a] [-b] [-e] [-n] [-o] [-p proto] [-r] [-s] [-v] [interval]

VARIOUS OPTIONS AVAILABLE WITH THE NETSTAT COMMAND

[-a] [-b] [-e] [-n] [-o] [-r]

Displays all connections and listening ports. Displays the executable involved in creating each connection or listening port. Displays Ethernet statistics. This may be combined with the -s option. Displays addresses and port numbers in numerical form. Displays the owning process ID associated with each connection. Displays the routing table.

[-s] Displays per-protocol statistics. By default, statistics are shown for IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6. [-v] When used in conjunction with -b, will display sequence of components involved in creating the connection or listening port for all executables.

IPCONFIG COMMAND Ipconfig is a DOS utility that can be used from MS-DOS and a MS-DOS shell to display the network settings currently assigned and given by a network. SYNTAX: ipconfig [/? | /all | /renew [adapter] | /release [adapter] |/flushdns | /displaydns | /registerdns | /showclassid adapter |/setclassid adapter [classid] ]

VARIOUS OPTIONS AVAILABLE WITH THE IPCONFIG COMMAND [/all] Display full configuration information. Release the IP address for the specified adapter. Renew the IP address for the specified adapter. Purges the DNS Resolver cache.

[/release] [/renew] [/flushdns]

[/registerdns] Refreshes all DHCP leases and re-registers DNS names. [/displaydns] Display the contents of the DNS Resolver Cache.

[/showclassid] Displays all the dhcp class IDs allowed for adapter. [/setclassid] Modifies the dhcp class id.

7.Creation of a batch file to switch between two IP addresses using NETSH

SOLUTION: 1.Open notepad and create a file with ".BAT" extension. 2.Code is "netsh int ip set address name = "Local Area Connection" source = static addr = 65.88.48.77 mask = 255.255.255.224" 3.Save this file. 4.open Command prompt and write "netsh interface ip show config" to check IP address. 5.Click on the batch file. 6.Open Command prompt and write "netsh interface ip show config" to check change IP address.

/*8. Calculation of CRC of a data*/

#include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int i,j,n,g,a,arr[20],gen[20],b[20],q[20],x[20],check,s; check=0; clrscr(); printf("\n\n\t ****** CYCLIC REDUNDANCY CHECK ****** "); printf("\n\t Transmitter side:"); printf("\n\t Enter no. of data bits: "); scanf("%d",&n); printf("\n\t Enter the data to be sent: \n"); for(i=0;i<n;i++) scanf("%d",&arr[i]); printf("\n\t Enter no. of divisor bits: "); scanf("%d",&g); do { printf("\n\t Enter the generator data: \n"); for(j=0;j<g;j++) scanf("%d",&gen[j]); }while(gen[0]!=1);

printf("\n\t The divisor is:"); for(j=0;j<g;j++) printf("%d",gen[j]); a=n+(g-1); printf("\n\t The transmitter side data is:"); for(i=0;i<j;++i) arr[n+i]=0; for(i=0;i<a;++i) printf("%d",arr[i]); for(i=0;i<n;++i) q[i]= arr[i]; for(i=0;i<n;++i) { if(arr[i]==0) { for(j=i;j<g+i;++j) arr[j] = arr[j]^0; } else { arr[i] = arr[i]^gen[0]; arr[i+1]=arr[i+1]^gen[1]; arr[i+2]=arr[i+2]^gen[2]; arr[i+3]=arr[i+3]^gen[3]; }

} printf("\n\t The CRC is :"); for(i=n;i<a;++i) printf("%d",arr[i]); for(i=0;i<g-1;++i) x[i]=arr[i]; s=n+a; for(i=n;i<s;i++) q[i]=arr[i]; printf("\n"); for(i=0;i<a;i++) printf("%d",q[i]); getch(); clrscr(); printf("\n\t Receiver side:"); printf("\n\t Enter no. of data bits received: "); scanf("%d",&n); printf("\n\t Enter the data received: \n"); for(i=0;i<n;i++) scanf("%d",&arr[i]); for(i=n,j=g-1;i<a,j<0;i++,j--) arr[i]=q[j]; printf("\n\t The receiver side data is:"); for(i=0;i<a;++i) printf("%d",arr[i]);

for(i=0;i<n;++i) q[i]=arr[i]; for(i=0;i<n;++i) { if(arr[i]==0) { for(j=i;j<g+i;++j) arr[j] = arr[j]^0; } else { arr[i] = arr[i]^gen[0]; arr[i+1]=arr[i+1]^gen[1]; arr[i+2]=arr[i+2]^gen[2]; arr[i+3]=arr[i+3]^gen[3]; } } printf("\n\t The CRC at the receiver is:"); for(i=n;i<a;++i) printf("%d",arr[i]); s=n+a; for(i=n;i<s;i++) q[i]=arr[i]; printf("\n"); i=0;

while(i<a) { if(q[i]==0) check=0; else check=1; i++; } printf("\n\n Result of CRC Error detection is: "); if(check==0) printf("\n\t Data is accepted successfully!"); else printf("\n Resend the data again!"); getch(); }

//Output:-8. ****** CYCLIC REDUNDANCY CHECK ****** Transmitter side: Enter no. of data bits: 6

Enter the data to be sent: 100100

Enter no. of divisor bits: 4 Enter the generator data: 1101 The divisor is: 1101 The transmitter side data is:100100000 The CRC is: 001 100100001 Receiver side: Enter no. of data bits received: 6

Enter the data received: 100100 The receiver side data is:100100001 The CRC at the receiver is:000 100100000 Result of CRC Error detection is: Data is accepted successfully!

9.Write a working program to download videos from youtube


HTML Front End <html> <head> <title>YouTube Downloader</title> </head> <body> <form action="youtube.php" method="post"> <b>YouTube URL:</b> <input type="Text" name="youtubeurl" size="35" value=""> <br> <input type="submit" value="Download Video"> </form> </body> </html>

Back End PHP Script


<?php

$VideoURL =$_POST["youtubeurl"]; header("Location: " . $VideoURL);

?>

10.Capturing Ethernet frames using Wireshark

1. Capturing Lets begin by capturing a set of Ethernet frames to study. Do the following1: First, make sure your browsers cache is empty. (To do this under Netscape 7.0, select Edit->Preferences->Advanced->Cache and clear the memory and disk cache. For Internet Explorer, select Tools->Internet Options->Delete Files. For Firefox select Tools->Clear Private Data.

Start up the Wireshark packet sniffer Enter the following URL into your browser http://gaia.cs.umass.edu/wireshark-labs/HTTP-ethereal-lab-file3.html Stop Wireshark packet capture. First, find the packet numbers (the leftmost column in the upper Wireshark window) of the HTTP GET message that was sent from your computer to gaia.cs.umass.edu, as well as the beginning of the HTTP response message sent to your computer by gaia.cs.umass.edu. You should see a screen that looks something like this (where packet 4 in the screen shot below contains the HTTP GET message) change Wiresharks listing of captured packets window so that it shows information only about protocols below IP. To have Wireshark do this, select Analyze->Enabled Protocols. Then uncheck the IP box and select OK. You should now see an Wireshark window that looks like: In order to answer the following questions, youll need to look into the packet details and packet contents windows (the middle and lower display windows in Wireshark). Select the Ethernet frame containing the HTTP GET message. (Recall that the HTTP

GET message is carried inside of a TCP segment, which is carried inside of an IP datagram, which is carried inside of an Ethernet frame; reread section 1.7.2 in the text if you find this nesting a bit confusing). Expand the Ethernet II information in the packet details window. Note that the contents of the Ethernet frame (header as well as payload) are displayed in the packet contents window.

Das könnte Ihnen auch gefallen