· 9 years ago · Apr 21, 2017, 06:10 PM
1Navaneethan
2
3question one
4Implement echo server and client in java using UDP sockets.
5
6Client program – ServerEcho.java
7
8import java.net.*;
9import java.util.*;
10
11public class ServerEcho
12{
13 public static void main( String args[]) throws Exception
14 {
15 DatagramSocket dsock = new DatagramSocket(7);
16 byte arr1[] = new byte[150];
17 DatagramPacket dpack = new DatagramPacket(arr1, arr1.length );
18
19 while(true)
20 {
21 dsock.receive(dpack);
22
23 byte arr2[] = dpack.getData();
24 int packSize = dpack.getLength();
25 String s2 = new String(arr2, 0, packSize);
26
27 System.out.println( new Date( ) + " " + dpack.getAddress( ) + " : " + dpack.getPort( ) + " "+ s2);
28 dsock.send(dpack);
29 }
30 }
31}
32
33Client program – ClientEcho.java
34import java.net.*;
35import java.util.*;
36
37public class ClientEcho
38{
39 public static void main( String args[] ) throws Exception
40 {
41 InetAddress add = InetAddress.getByName("snrao");
42
43 DatagramSocket dsock = new DatagramSocket( );
44 String message1 = "This is client calling";
45 byte arr[] = message1.getBytes( );
46 DatagramPacket dpack = new DatagramPacket(arr, arr.length, add, 7);
47 dsock.send(dpack); // send the packet
48 Date sendTime = new Date(); // note the time of sending the message
49
50 dsock.receive(dpack); // receive the packet
51 String message2 = new String(dpack.getData( ));
52 Date receiveTime = new Date( ); // note the time of receiving the message
53 System.out.println((receiveTime.getTime( ) - sendTime.getTime( )) + " milliseconds echo time for " + message2);
54 }
55}
56
57
58 OR
59
60import java.net.*;
61 import java.util.*;
62 public class EchoServer
63{
64 public static void main( String args[]) throws Exception
65 {
66 DatagramSocket dsock = new DatagramSocket(7);
67byte arr1[] = new byte[150];
68DatagramPacket dpack = new DatagramPacket(arr1, arr1.length );
69while(true)
70{ dsock.receive(dpack);
71byte arr2[] = dpack.getData();
72 int packSize = dpack.getLength();
73String s2 = new String(arr2, 0, packSize);
74System.out.println( new Date( ) + " " + dpack.getAddress( ) + " : " + dpack.getPort( ) + " "+ s2);
75dsock.send(dpack);
76}
77}
78}----------------------------------
79import java.net.*;
80import java.util.*;
81 public class EchoClient
82{ public static void main( String args[] ) throws Exception {
83InetAddress add = InetAddress.getByName("127.0.0.1");
84DatagramSocket dsock = new DatagramSocket( );
85 String message1 = "This is client calling";
86 byte arr[] = message1.getBytes( );
87 DatagramPacket dpack = new DatagramPacket(arr, arr.length, add, 7);
88 dsock.send(dpack); // send the packet
89Date sendTime = new Date( ); // note the time of sending the message
90dsock.receive(dpack); // receive the packet
91String message2 = new String(dpack.getData( ));
92 Date receiveTime = new Date( ); // note the time of receiving the message
93 System.out.println((receiveTime.getTime( ) - sendTime.getTime( )) + " milliseconds echo time for " + message2);
94 }
95 }
96
97
98
99
100
101
102
103
104question 2
105Implement a simple message transfer from client to server process using UDP.
106import java.io.*;
107import java.net.*;
108class UDPServerss {
109public static void main(String args[]) throws Exception {
110 DatagramSocket serverSocket = new DatagramSocket(9876);
111
112 byte[] receiveData = new byte[1024];
113 byte[] sendData = new byte[1024];
114 while(true) {
115
116 DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
117 serverSocket.receive(receivePacket);
118 String sentence = new String( receivePacket.getData());
119 System.out.println("RECEIVED: " + sentence);
120 InetAddress IPAddress = receivePacket.getAddress();
121 int port = receivePacket.getPort();
122 String capitalizedSentence = sentence.toUpperCase();
123 sendData = capitalizedSentence.getBytes();
124 DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port);
125 serverSocket.send(sendPacket);
126 }
127}
128}
129import java.io.*;
130import java.net.*;
131 class UDPClientssss {
132 public static void main(String args[]) throws Exception {
133 BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
134 DatagramSocket clientSocket = new DatagramSocket();
135 InetAddress IPAddress = InetAddress.getByName("localhost");
136 byte[] sendData = new byte[1024];
137 byte[] receiveData = new byte[1024];
138 String sentence = inFromUser.readLine();
139 sendData = sentence.getBytes();
140 DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
141 clientSocket.send(sendPacket);
142 DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
143 clientSocket.receive(receivePacket);
144 String modifiedSentence = new String(receivePacket.getData());
145 System.out.println("FROM SERVER:" + modifiedSentence);
146 clientSocket.close();
147 }
148 }
149
150
151
152
153
154
155question 3
156 Simple chat application in java using datagram socket and datagram packet
157Algorithm
158Start the UDP chat program
159Import the package java.net.*;
160Declare the datagramsocket,datagrampacket,BufferedReader,InetAddress.
161Start the main function
162In the main function using while loop it perform the loop until str.equals is STOP
163There important while loop function are
164clientsocket = new DatagramSocket(cport);
165dp = new DatagramPacket(buf, buf.length);
166dis = new BufferedReader(new
167InputStreamReader(System.in));
168ia = InetAddress.getLocalHost(); f it is stop then break the while loop
169Terminate the UDP client program
170source code java programming UDP Chat server
171import java.io.*;
172import java.net.*;
173class UDPServer
174{
175public static DatagramSocket serversocket;
176public static DatagramPacket dp;
177public static BufferedReader dis;
178public static InetAddress ia;
179public static byte buf[] = new byte[1024];
180public static int cport = 789,sport=790;
181public static void main(String[] a) throws IOException
182{
183serversocket = new DatagramSocket(sport);
184dp = new DatagramPacket(buf,buf.length);
185dis = new BufferedReader
186(new InputStreamReader(System.in));
187ia = InetAddress.getLocalHost();
188System.out.println("Server is Running...");
189while(true)
190{
191serversocket.receive(dp);
192String str = new String(dp.getData(), 0,
193dp.getLength());
194if(str.equals("STOP"))
195{
196System.out.println("Terminated...");
197break;
198}
199System.out.println("Client: " + str);
200String str1 = new String(dis.readLine());
201buf = str1.getBytes();
202serversocket.send(new
203DatagramPacket(buf,str1.length(), ia, cport));
204}
205}
206}
207
208Output:-
209C:\IPLAB>javac UDPServer.java
210C:\IPLAB>java UDPServer
211Server is Running...
212Client: Hello
213Welcome
214Terminated...
215
216source code java programming UDP Chat Client
217import java.io.*;
218import java.net.*;
219class UDPClient
220{
221public static DatagramSocket clientsocket;
222public static DatagramPacket dp;
223public static BufferedReader dis;
224public static InetAddress ia;
225public static byte buf[] = new byte[1024];
226public static int cport = 789, sport = 790;
227public static void main(String[] a) throws IOException
228{
229clientsocket = new DatagramSocket(cport);
230dp = new DatagramPacket(buf, buf.length);
231dis = new BufferedReader(new
232InputStreamReader(System.in));
233ia = InetAddress.getLocalHost();
234System.out.println("Client is Running... Type 'STOP'
235to Quit");
236while(true)
237{
238String str = new String(dis.readLine());
239buf = str.getBytes();
240if(str.equals("STOP"))
241{
242System.out.println("Terminated...");
243clientsocket.send(new
244DatagramPacket(buf,str.length(), ia,
245sport));
246break;
247}
248clientsocket.send(new DatagramPacket(buf,
249str.length(), ia, sport));
250clientsocket.receive(dp);
251String str2 = new String(dp.getData(), 0,
252dp.getLength());
253System.out.println("Server: " + str2);
254}
255}
256}
257
258Output UDP Chat Client
259C:\IPLAB>javac UDPClient.java
260C:\IPLAB>java UDPClient
261Client is Running... Type ‘STOP’ to Quit
262Hello
263Server: Welcome
264STOP
265Terminated...
266BB / REC - 41
267
268
269
270 or
271
272
273 Client interface:
274
275 import java.awt.*;
276 import javax.swing.*;
277 public class UDPClient extends JFrame
278 {
279 // Variables
280 private JFrame frame;
281 private JPanel panel;
282 private JLabel label;
283 private JButton sendbutton;
284 private JTextField textfield;
285 private JTextArea textarea;
286 private JScrollPane scrollpane;
287
288 public static void main (String args[]) {
289
290 new UDPClient();
291 }
292
293 // Constructor
294 public UDPClient() {
295
296 frame = this;
297 panel = new JPanel(new GridBagLayout());
298 panel.setBackground(Color.cyan);
299 frame.setTitle("Chat Applet Client");
300 frame.getContentPane().add(panel, BorderLayout.NORTH);
301 frame.setVisible(true);
302 frame.setSize(430, 364);
303 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
304 //frame.setResizable(false);
305 GridBagConstraints c = new GridBagConstraints();
306 c.insets = new Insets(5, 5, 5, 5);
307
308 // Server address label
309 label = new JLabel("Server:");
310 c.fill = GridBagConstraints.HORIZONTAL;
311 c.gridx = 0;
312 c.gridy = 0;
313 panel.add(label, c);
314
315 // Server address textfield
316 textfield = new JTextField(20);
317 c.fill = GridBagConstraints.HORIZONTAL;
318 c.gridx = 1;
319 c.gridy = 0;
320 panel.add(textfield, c);
321
322 // 'Port#:' label
323 label = new JLabel("Port# :");
324 c.fill = GridBagConstraints.HORIZONTAL;
325 c.gridx = 2;
326 c.gridy = 0;
327 panel.add(label, c);
328
329 // Port# textfield
330 textfield = new JTextField(6);
331 c.fill = GridBagConstraints.HORIZONTAL;
332 c.gridx = 3;
333 c.gridy = 0;
334 panel.add(textfield, c);
335
336 // 'Conversation:' label
337 label = new JLabel("Conversation:");
338 c.fill = GridBagConstraints.HORIZONTAL;
339 c.gridx = 0;
340 c.gridy = 1;
341 c.gridwidth = 4;
342 panel.add(label, c);
343
344 // Conversation Window
345 textarea = new JTextArea(10, 2);
346 scrollpane = new JScrollPane(textarea);
347 textarea.setLineWrap(true);
348 textarea.setWrapStyleWord(true);
349 textarea.setEditable(false);
350 c.fill = GridBagConstraints.HORIZONTAL;
351 c.gridx = 0;
352 c.gridy = 2;
353 c.gridwidth = 4;
354 panel.add(scrollpane, c);
355
356 // 'Message:' label
357 label = new JLabel("Message to Send:");
358 c.fill = GridBagConstraints.HORIZONTAL;
359 c.gridx = 0;
360 c.gridy = 3;
361 panel.add(label, c);
362
363 // Message Window
364 textarea = new JTextArea(2, 2);
365 scrollpane = new JScrollPane(textarea);
366 textarea.setLineWrap(true);
367 textarea.setWrapStyleWord(true);
368 c.fill = GridBagConstraints.HORIZONTAL;
369 c.gridx = 0;
370 c.gridy = 4;
371 c.gridwidth = 4;
372 panel.add(scrollpane, c);
373
374 // 'Send' button
375 sendbutton = new JButton("Send");
376 c.fill = GridBagConstraints.HORIZONTAL;
377 c.gridx = 0;
378 c.gridy = 5;
379 c.gridwidth = 4;
380 panel.add(sendbutton, c);
381 }
382 }
383
384
385
386
387
388Server interface:
389
390 import java.awt.*;
391 import javax.swing.*;
392 public class UDPServer extends JFrame {
393 // Variables
394 private JFrame frame;
395 private JPanel panel;
396 private JLabel label;
397 private JButton startbutton;
398 private JButton stopbutton;
399 private JButton sendbutton;
400 private JTextField textfield;
401 private JTextArea textarea;
402 private JScrollPane scrollpane;
403
404 //http://www.youtube.com/watch?v=IkEz5tW5bok
405 public static void main (String args[]) {
406
407 new UDPServer();
408 }
409
410 // Constructor
411 public UDPServer() {
412
413 frame = this;
414 panel = new JPanel(new GridBagLayout());
415 panel.setBackground(Color.darkGray);
416 frame.setTitle("Chat Applet Server");
417 frame.getContentPane().add(panel, BorderLayout.NORTH);
418 frame.setVisible(true);
419 //frame.pack();
420
421 frame.setSize(430, 364);
422 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
423 frame.setResizable(true);
424 GridBagConstraints c = new GridBagConstraints();
425 c.insets = new Insets(5, 5, 5, 5);
426
427 // 'Start Server' button
428 startbutton = new JButton("Start Server");
429 startbutton.setPreferredSize(new Dimension(130,20));
430 c.fill = GridBagConstraints.HORIZONTAL;
431 c.gridx = 0;
432 c.gridy = 0;
433 c.gridwidth = 1;
434 panel.add(startbutton, c);
435
436 // 'Stop Server' button
437 stopbutton = new JButton("Stop Server");
438 stopbutton.setPreferredSize(new Dimension(130,20));
439 c.fill = GridBagConstraints.HORIZONTAL;
440 c.gridx = 1;
441 c.gridy = 0;
442 c.gridwidth = 1;
443 panel.add(stopbutton, c);
444
445 // 'Port#:' label
446 label = new JLabel("Port# :");
447 label.setForeground(Color.white);
448 c.fill = GridBagConstraints.HORIZONTAL;
449 c.gridx = 2;
450 c.gridy = 0;
451 panel.add(label, c);
452
453 // Port# textfield
454 textfield = new JTextField(6);
455 c.fill = GridBagConstraints.HORIZONTAL;
456 c.gridx = 3;
457 c.gridy = 0;
458 panel.add(textfield, c);
459
460 // 'Conversation:' label
461 label = new JLabel("Conversation:");
462 label.setForeground(Color.white);
463 c.fill = GridBagConstraints.HORIZONTAL;
464 c.gridx = 0;
465 c.gridy = 1;
466 c.gridwidth = 4;
467 panel.add(label, c);
468
469 // Conversation Window
470 textarea = new JTextArea("<Server not yet started!>", 10, 2);
471 scrollpane = new JScrollPane(textarea);
472 textarea.setLineWrap(true);
473 textarea.setWrapStyleWord(true);
474 textarea.setEditable(false);
475 c.fill = GridBagConstraints.HORIZONTAL;
476 c.gridx = 0;
477 c.gridy = 2;
478 c.gridwidth = 4;
479 panel.add(scrollpane, c);
480
481 // 'Message:' label
482 label = new JLabel("Message to Send:");
483 label.setForeground(Color.white);
484 c.fill = GridBagConstraints.HORIZONTAL;
485 c.gridx = 0;
486 c.gridy = 3;
487 panel.add(label, c);
488
489 // Message Window
490 textarea = new JTextArea(2, 2);
491 scrollpane = new JScrollPane(textarea);
492 textarea.setLineWrap(true);
493 textarea.setWrapStyleWord(true);
494 c.fill = GridBagConstraints.HORIZONTAL;
495 c.gridx = 0;
496 c.gridy = 4;
497 c.gridwidth = 4;
498 panel.add(scrollpane, c);
499
500 // 'Send' button
501 sendbutton = new JButton("Send");
502 c.fill = GridBagConstraints.HORIZONTAL;
503 c.gridx = 0;
504 c.gridy = 5;
505 c.gridwidth = 4;
506 panel.add(sendbutton, c);
507 }
508 }
509
510
511
512
513
514
515question 4-----------------------------
516UDP Program – DNS CLIENT-SERVER
517
518UDP Program (DNS CLIENT-SERVER)
519
520AIM : To create a client server program to Domain Name System using the UDP protocol client server.
521
522ALGORITHM
523
524Server
525
526 Declare the necessary arrays and variables.
527 Set server port address using socket().
528 Get the current message.
529 Connect to the client.
530 Stop the process.
531
532Client
533
534 Set the client machine address.
535 Connect to the server.
536 Read from the server the current message.
537 Display the current message.
538 Close the connection.
539
540PROGRAM:
541
542UDPclient
543
544import java .io.*;
545
546import java.net.*;
547
548classUDPclient
549
550{
551
552public static DatagramSocket ds;
553
554public static intclientport=789,serverport=790;
555
556public static void main(String args[])throws Exception
557
558{
559
560byte buffer[]=new byte[1024];
561
562ds=new DatagramSocket(serverport);
563
564BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));
565
566System.out.println(“server waitingâ€);
567
568InetAddressia=InetAddress.getLocalHost();
569
570while(true)
571
572{
573
574System.out.println(“Client:â€);
575
576String str=dis.readLine();
577
578if(str.equals(“endâ€))
579
580break;
581
582buffer=str.getBytes();
583
584ds.send(new DatagramPacket(buffer,str.length(),ia,clientport));
585
586DatagramPacket p=new DatagramPacket(buffer,buffer.length);
587
588ds.receive(p);
589
590String psx=new String(p.getData(),0,p.getLength());
591
592System.out.println(“Server:†+ psx);
593
594}
595
596}
597
598}
599
600UDP server
601
602import java.io.*;
603
604import java.net.*;
605
606classUDPserver
607
608{
609
610public static DatagramSocket ds;
611
612public static byte buffer[]=new byte[1024];
613
614public static intclientport=789,serverport=790;
615
616public static void main(String args[])throws Exception
617
618{
619
620ds=new DatagramSocket(clientport);
621
622System.out.println(“press ctrl+c to quit the programâ€);
623
624BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));
625
626InetAddressia=InetAddress.getLocalHost();
627
628while(true)
629
630{
631
632DatagramPacket p=new DatagramPacket(buffer,buffer.length);
633
634ds.receive(p);
635
636String psx=new String(p.getData(),0,p.getLength());
637
638System.out.println(“Client:†+ psx);
639
640InetAddressib=InetAddress.getByName(psx);
641
642System.out.println(“Server output:â€+ib);
643
644String str=dis.readLine();
645
646if(str.equals(“endâ€))
647
648break;
649
650buffer=str.getBytes();
651
652ds.send(new DatagramPacket(buffer,str.length(),ia,serverport));
653
654}
655
656}
657
658}
659
660OUTPUT:
661
662UDPclient
663
664C:\Program Files\Java\jdk1.6.0\bin>javac UDPclient.java
665
666C:\Program Files\Java\jdk1.6.0\bin>java UDPclient
667
668Server waiting
669
670Client:www.yahoo.com
671
672UDPserver
673
674C:\Program Files\Java\jdk1.6.0\bin>javac UDPserver.java
675
676C:\Program Files\Java\jdk1.6.0\bin>java UDPserver
677
678Press ctrl+c to quit the program
679
680Client:www.yahoo.com
681
682Server output:www.yahoo.com/106.10.170.115
683
684RESULT:
685
686Thus client server program to Domain Name System using the UDP protocol client server has been executed and verified successfully.
687
688
689
690
691
692QUESTION 5------------------------------------------------
693UDP DATE SERVER
694
695Server Program >>>>> Server.java
696
697
698import java.net.*;
699import java.io.*;
700import java.util.*;
701
702public class Server {
703
704public static void main(String[] args) throws Exception{
705
706DatagramSocket ss=new DatagramSocket(1234);
707
708while(true){
709
710System.out.println("Server is up....");
711
712byte[] rd=new byte[100];
713byte[] sd=new byte[100];
714
715DatagramPacket rp=new DatagramPacket(rd,rd.length);
716
717ss.receive(rp);
718
719InetAddress ip= rp.getAddress();
720
721int port=rp.getPort();
722
723Date d=new Date(); // getting system time
724
725String time= d + ""; // converting it to String
726
727sd=time.getBytes(); // converting that String to byte
728
729DatagramPacket sp=new DatagramPacket(sd,sd.length,ip,port);
730
731ss.send(sp);
732
733rp=null;
734
735System.out.println("Done !! ");
736
737}
738
739}
740
741}
742
743
744Client program >>>>>>>>> Clientnew.java
745import java.net.*;
746import java.io.*;
747
748public class Clientnew {
749
750public static void main(String[] args) throws Exception{
751
752 System.out.println("Server Time >>>>");
753
754 DatagramSocket cs=new DatagramSocket();
755
756 InetAddress ip=InetAddress.getByName("localhost");
757
758 byte[] rd=new byte[100];
759 byte[] sd=new byte[100];
760
761 DatagramPacket sp=new DatagramPacket(sd,sd.length,ip,1234);
762
763 DatagramPacket rp=new DatagramPacket(rd,rd.length);
764
765 cs.send(sp);
766
767 cs.receive(rp);
768
769 String time=new String(rp.getData());
770
771 System.out.println(time);
772
773 cs.close();
774
775}
776
777}
778
779
780
781
782
783
784
785
786
787------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
788SIR UPLOADED MATERIAL
789
790
7911)Write a program to list all ports hosting a TCP server in a specified host.
792
793import java.net.*;
794import java.io.*;
795public class ports{
796public static void main(String args[])
797{
798for(int i=1;i<1024;i++)
799{
800try{
801Socket s=new Socket("127.0.0.1",i);
802System.out.println("There is server on port"+i+"of 127.0.0.1");
803}
804catch(UnknownHostException e){
805System.err.println(e);
806break;
807}
808catch(IOException e){
809//must not be server on this port
810}
811}
812}
813}
814
8152)Write a program to display the server’s date and time details at the client end.
816
817import java.io.IOException;
818import java.io.PrintWriter;
819import java.net.ServerSocket;
820import java.net.Socket;
821import java.util.Date;
822
823public class dateserver {
824
825 public static void main(String[] args) throws IOException {
826 ServerSocket listener = new ServerSocket(9090);
827 try {
828 while (true) {
829 Socket socket = listener.accept();
830 try {
831 PrintWriter out =
832 new PrintWriter(socket.getOutputStream(), true);
833 out.println(new Date().toString());
834 } finally {
835 socket.close();
836 }
837 }
838 }
839 finally {
840 listener.close();
841 }
842 }
843}
844
845------------------------------
846import java.io.*;
847import java.net.Socket;
848
849public class dateClient {
850
851 public static void main(String[] args) throws IOException {
852 Socket s = new Socket("127.0.0.1", 9090);
853 BufferedReader input =
854 new BufferedReader(new InputStreamReader(s.getInputStream()));
855 String answer = input.readLine();
856 System.out.println("The date and time details are "+answer );
857
858 System.exit(0);
859 }
860}
861
862
8633)Write a program to display the client’s address at the server end.
864
865
866import java.io.*;
867import java.net.*;
868
869public class ServerAddr
870{
871public static void main(String args[]) throws IOException
872{
873try
874{
875ServerSocket ss = new ServerSocket(6666);
876System.out.println("Waiting for client.....");
877
878Socket s = ss.accept();
879System.out.println("Connected to client....");
880
881DataInputStream in = new DataInputStream (s.getInputStream());
882String line = null;
883line = in.readUTF();
884System.out.println("Client's IP adress: " + line);
885}
886catch (Exception e)
887{
888e.printStackTrace();
889}
890}
891}
892
893--------------------------------
894
895import java.io.*;
896import java.net.*;
897
898public class ClientAddr
899{
900public static void main(String args[]) throws IOException
901{
902try
903{
904InetAddress ipaddress = InetAddress.getByName("");
905Socket s = new Socket(ipaddress,6666);
906
907System.out.println("Connected to the server...");
908DataOutputStream out = new DataOutputStream(s.getOutputStream());
909
910String line = null;
911System.out.println("Sending my IP Address to server...");
912
913line=ipaddress.getHostAddress();
914
915out.writeUTF(line);
916out.flush();}
917catch (Exception e)
918{
919e.printStackTrace();
920}
921}
922}
923
9244)Implement a simple message transfer from client to server process using TCP/IP.
925
926import java.io.*;
927import java.net.*;
928
929public class Tcpserver
930{
931public static void main(String args[]) throws IOException
932{
933try
934{
935ServerSocket ss = new ServerSocket(6666);
936System.out.println("Waiting for client.....");
937
938Socket s = ss.accept();
939System.out.println("Connected to client....");
940
941DataInputStream in = new DataInputStream (s.getInputStream());
942String line = null;
943line = in.readUTF();
944System.out.println("Mesage from Client:" + line);
945}
946catch (Exception e)
947{
948e.printStackTrace();
949}
950}
951}
952
953--------------------------------------
954import java.io.*;
955import java.net.*;
956
957public class TCPClient
958{
959public static void main(String args[]) throws IOException
960{
961try
962{
963InetAddress ipaddress = InetAddress.getByName("");
964Socket s = new Socket(ipaddress,6666);
965DataInputStream read = new DataInputStream(System.in);
966System.out.println("Connected to the server...");
967DataOutputStream out = new DataOutputStream(s.getOutputStream());
968
969String line = null;
970System.out.println("Write a message to the server..");
971
972line=read.readLine();
973out.writeUTF(line);
974out.flush();}
975catch (Exception e)
976{
977e.printStackTrace();
978}
979}
980}
981
9825)Develop a TCP client/server application for transferring a text file from client to server
983
984
985CLIENt:
986import java.io.*;
987 import java.net.*;
988import java.util.*;
989public class FTPClient {
990public static void main(String args[]) throws Exception
991
992{
993 Socket ss = new Socket("localhost",5000);
994while(true)
995{
996
997Scanner pbn = new Scanner(System.in);
998System.out.println("Enter the path of the file ");
999String path = pbn.nextLine();
1000System.out.println(path);
1001
1002File f = new File(path);
1003FileInputStream fis = new FileInputStream(f);
1004
1005BufferedInputStream bis = new BufferedInputStream(fis);
1006System.out.println("Sending file...");
1007
1008System.out.println("File sent");
1009
1010 }
1011
1012 }
1013}
1014server:
1015
1016//////////////////
1017import java.io.*;
1018import java.net.*;
1019import java.util.*;
1020public class FTPServer {
1021public static void main(String args[]) throws IOException
1022{ServerSocket ss = new ServerSocket(5000);
1023
1024 Scanner pbn = new Scanner(System.in);
1025 boolean flag = true;
1026 while(flag)
1027 {
1028 flag = false;
1029 try
1030 {System.out.println("waiting...");
1031Socket s = ss.accept();
1032System.out.println("Accepted connection "+s);
1033 System.out.println("Enter the path where you want to store the file");
1034 String path1 = pbn.nextLine();
1035 FileOutputStream fos = new FileOutputStream(path1);
1036 BufferedOutputStream bos = new BufferedOutputStream(fos);
1037 InputStream is = s.getInputStream();
1038 byte[] b = new byte[600000];
1039 int n = 0;
1040 int o = 0;
1041 while((n=is.read(b,o,b.length-o))>=0)
1042 {
1043 o+=n;
1044 }
1045 bos.write(b,0,o);
1046
1047 bos.flush();
1048 System.out.println("File Received");
1049 }
1050
1051 catch(FileNotFoundException f)
1052 {
1053 flag = true;
1054 String msg = f.getMessage();
1055 System.out.println("Error Message:"+msg);
1056 System.out.println("Please Enter a correct file path");
1057 }
1058 }
1059
1060 }
1061}
1062
1063
10646. Implement a TCP based server program to authenticate the client’s User Name and Password. The validity of the client must be sent as the reply message to the client and display it on the standard output.
1065
1066import java.io.*;
1067import java.net.*;
1068
1069public class AuthServer
1070{
1071 public static void main(String args[]) throws IOException
1072 {
1073 try
1074 {
1075 ServerSocket ss = new ServerSocket(6666);
1076 System.out.println("Waiting for client.....");
1077 Socket s = ss.accept();
1078 System.out.println("Connected to client....");
1079
1080 DataInputStream in = new DataInputStream (s.getInputStream());
1081 DataOutputStream out = new DataOutputStream (s.getOutputStream());
1082
1083 String line = null;
1084 String line1 = null;
1085 String sendline = null;
1086
1087
1088line = in.readUTF();
1089line1 = in.readUTF();
1090 if((line.equals("aid")|| line.equals("bid"))&&((line1.equals("apass")|| line1.equals("bpass"))))
1091 {
1092 sendline ="Valid user id and password.Successfully logged in !!!!";
1093 out.writeUTF(sendline);
1094 out.flush();
1095
1096 }
1097 else
1098
1099 {
1100 sendline ="Invalid details";
1101 out.writeUTF(sendline);
1102 out.flush();
1103 }
1104
1105 }
1106 catch (Exception e)
1107 {
1108 e.printStackTrace();
1109 }
1110 }
1111}
1112
1113import java.io.*;
1114import java.net.*;
1115
1116public class AuthClient
1117{
1118 public static void main(String args[]) throws IOException
1119 {
1120 try
1121 {
1122 InetAddress ipaddress = InetAddress.getByName("127.0.0.1");
1123 Socket s = new Socket(ipaddress,6666);
1124
1125 System.out.println("Connected to the server...");
1126
1127 DataInputStream read = new DataInputStream(System.in);
1128
1129 DataInputStream in = new DataInputStream(s.getInputStream());
1130 DataOutputStream out = new DataOutputStream(s.getOutputStream());
1131
1132 String line = null;
1133 String line1 = null;
1134 String receiveline = null;
1135
1136 System.out.println("Enter User id ");
1137 line = read.readLine();
1138 out.writeUTF(line);
1139 out.flush();
1140
1141System.out.println("Enter Password ");
1142line1 = read.readLine();
1143out.writeUTF(line1);
1144out.flush();
1145
1146
1147 receiveline = in.readUTF();
1148 System.out.println("SERVER: " + receiveline);
1149
1150
1151 }
1152 catch (Exception e)
1153 {
1154 e.printStackTrace();
1155 }
1156 }
1157}
1158
11597. Write a program to develop a simple (text based) Chat application using TCP/IP.
1160//chat
1161import java.io.*;
1162import java.net.*;
1163
1164public class TCPserver
1165{
1166 public static void main(String args[]) throws IOException
1167 {
1168 try
1169 {
1170 ServerSocket ss = new ServerSocket(6666);
1171 System.out.println("Waiting for client.....");
1172DataInputStream read = new DataInputStream(System.in);
1173 Socket s = ss.accept();
1174 System.out.println("Connected to client....");
1175
1176 DataInputStream in = new DataInputStream (s.getInputStream());
1177 DataOutputStream out = new DataOutputStream (s.getOutputStream());
1178
1179 String line = null;
1180
1181
1182 do
1183 {
1184 line = in.readUTF();
1185 System.out.println("CLIENT: " + line);
1186 line = read.readLine();
1187 out.writeUTF(line);
1188 out.flush();
1189
1190 System.out.println("Waiting for the next line.....");
1191 }while(!line.equals("bye"));
1192 }
1193 catch (Exception e)
1194 {
1195 e.printStackTrace();
1196 }
1197 }
1198}
1199
1200
1201//chat
1202import java.io.*;
1203import java.net.*;
1204
1205public class TCPClient
1206{
1207 public static void main(String args[]) throws IOException
1208 {
1209 try
1210 {
1211 InetAddress ipaddress = InetAddress.getByName("127.0.0.1");
1212 Socket s = new Socket(ipaddress,6666);
1213
1214 System.out.println("Connected to the server...");
1215
1216 DataInputStream read = new DataInputStream(System.in);
1217
1218 DataInputStream in = new DataInputStream(s.getInputStream());
1219 DataOutputStream out = new DataOutputStream(s.getOutputStream());
1220
1221 String line = null;
1222 String receiveline = null;
1223
1224 System.out.println("Enter data to send to the server: ");
1225
1226 do
1227 {
1228 System.out.print("CLIENT: ");
1229 line = read.readLine();
1230 out.writeUTF(line);
1231 out.flush();
1232
1233 receiveline = in.readUTF();
1234 System.out.println("SERVER: " + receiveline);
1235
1236 }while(!line.equals("bye"));
1237 }
1238 catch (Exception e)
1239 {
1240 e.printStackTrace();
1241 }
1242 }
1243}
1244
12458. Implement a simple message transfer from client to server process using UDP.
1246import java.io.*;
1247import java.net.*;
1248class UDPServerss {
1249public static void main(String args[]) throws Exception {
1250 DatagramSocket serverSocket = new DatagramSocket(9876);
1251
1252 byte[] receiveData = new byte[1024];
1253 byte[] sendData = new byte[1024];
1254 while(true) {
1255
1256 DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
1257 serverSocket.receive(receivePacket);
1258 String sentence = new String( receivePacket.getData());
1259 System.out.println("RECEIVED: " + sentence);
1260 InetAddress IPAddress = receivePacket.getAddress();
1261 int port = receivePacket.getPort();
1262 String capitalizedSentence = sentence.toUpperCase();
1263 sendData = capitalizedSentence.getBytes();
1264 DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port);
1265 serverSocket.send(sendPacket);
1266 }
1267}
1268}
1269import java.io.*;
1270import java.net.*;
1271 class UDPClientssss {
1272 public static void main(String args[]) throws Exception {
1273 BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
1274 DatagramSocket clientSocket = new DatagramSocket();
1275 InetAddress IPAddress = InetAddress.getByName("localhost");
1276 byte[] sendData = new byte[1024];
1277 byte[] receiveData = new byte[1024];
1278 String sentence = inFromUser.readLine();
1279 sendData = sentence.getBytes();
1280 DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
1281 clientSocket.send(sendPacket);
1282 DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
1283 clientSocket.receive(receivePacket);
1284 String modifiedSentence = new String(receivePacket.getData());
1285 System.out.println("FROM SERVER:" + modifiedSentence);
1286 clientSocket.close();
1287 }
1288 }
1289
12909. Write a program to implement an Echo UDP server. Test the working of the server by writing a client application.
1291import java.net.*;
1292 import java.util.*;
1293 public class EchoServer
1294{
1295 public static void main( String args[]) throws Exception
1296 {
1297 DatagramSocket dsock = new DatagramSocket(7);
1298byte arr1[] = new byte[150];
1299DatagramPacket dpack = new DatagramPacket(arr1, arr1.length );
1300while(true)
1301{ dsock.receive(dpack);
1302byte arr2[] = dpack.getData();
1303 int packSize = dpack.getLength();
1304String s2 = new String(arr2, 0, packSize);
1305System.out.println( new Date( ) + " " + dpack.getAddress( ) + " : " + dpack.getPort( ) + " "+ s2);
1306dsock.send(dpack);
1307}
1308}
1309}----------------------------------
1310import java.net.*;
1311import java.util.*;
1312 public class EchoClient
1313{ public static void main( String args[] ) throws Exception {
1314InetAddress add = InetAddress.getByName("127.0.0.1");
1315DatagramSocket dsock = new DatagramSocket( );
1316 String message1 = "This is client calling";
1317 byte arr[] = message1.getBytes( );
1318 DatagramPacket dpack = new DatagramPacket(arr, arr.length, add, 7);
1319 dsock.send(dpack); // send the packet
1320Date sendTime = new Date( ); // note the time of sending the message
1321dsock.receive(dpack); // receive the packet
1322String message2 = new String(dpack.getData( ));
1323 Date receiveTime = new Date( ); // note the time of receiving the message
1324 System.out.println((receiveTime.getTime( ) - sendTime.getTime( )) + " milliseconds echo time for " + message2);
1325 }
1326 }
1327
132810. Write a program to implement the DISCARD server using UDP. Test the working of the server by writing a client application. Let the server log the client details on its standard output.
1329import java.io.*;
1330import java.net.*;
1331public class UDPdiscardServer {
1332 public final static int DEFAULT_PORT=9;
1333 public final static int MAX_PACKET_SIZE=65507;
1334public static void main(String args[])
1335{
1336 int port=DEFAULT_PORT;
1337 byte[] buffer=new byte[MAX_PACKET_SIZE];
1338
1339 try{
1340 port=9;
1341 }
1342catch(Exception ex)
1343{}
1344 try{
1345 DatagramSocket server=new DatagramSocket(port);
1346DatagramPacket packet=new DatagramPacket(buffer,buffer.length);
1347
1348while(true)
1349{
1350 try{
1351 server.receive(packet);
1352 String s=new String(packet.getData(),0,packet.getLength(),"UTF-8");
1353 System.out.println(packet.getAddress()+" at port "+packet.getPort()+" says "+s);
1354 packet.setLength(buffer.length);
1355 }
1356 catch(IOException ex){ System.err.println(ex);}
1357}
1358
1359 }
1360 catch(SocketException ex)
1361 {System.err.println(ex);}
1362}
1363}
1364import java.io.*;
1365import java.net.*;
1366public class UDPdiscardClient {
1367 public final static int DEFAULT_PORT=9;
1368
1369public static void main(String args[])
1370{String hostname="localhost";
1371 int port=DEFAULT_PORT;
1372
1373
1374 try{
1375 InetAddress server=InetAddress.getByName(hostname);
1376 BufferedReader userInput=new BufferedReader(new InputStreamReader(System.in));
1377 DatagramSocket theSocket=new DatagramSocket();
1378
1379 while(true)
1380 {
1381 String theLine=userInput.readLine();
1382 if(theLine.equals(".")) break;
1383 byte[] data=theLine.getBytes("UTF-8");
1384 DatagramPacket theOutput=new DatagramPacket(data,data.length,server,port);
1385 theSocket.send(theOutput);
1386 }
1387 }
1388 catch(UnknownHostException ex)
1389 {System.err.println(ex);}
1390 catch(SocketException ex)
1391 {System.err.println(ex);}
1392 catch(IOException ioex)
1393 {System.err.println(ioex);}
1394}
1395}
1396Find the physical address of a host when its logical address is known (ARP protocol) using TCP/IP.
1397
1398import java.net.InetAddress;
1399import java.net.NetworkInterface;
1400import java.net.SocketException;
1401import java.net.UnknownHostException;
1402import java.util.Scanner;
1403
1404public class MacAddress {
1405 public static void main(String[] args)
1406 {
1407 try
1408 {
1409 Scanner console = new Scanner(System.in);
1410 System.out.println("Enter System Name: ");
1411 String ipaddr = console.nextLine();
1412 InetAddress address = InetAddress.getByName(ipaddr);
1413 System.out.println("address = "+address);
1414 NetworkInterface ni = NetworkInterface.getByInetAddress(address);
1415 if (ni!=null)
1416 {
1417 byte[] mac = ni.getHardwareAddress();
1418 if (mac != null)
1419 {
1420 System.out.print("MAC Address : ");
1421 for (int i=0; i<mac.length; i++)
1422 {
1423 System.out.format("%02X%s", mac[i], (i<mac.length - 1) ? "-" :"");
1424 }
1425 }
1426 else
1427 {
1428 System.out.println("Address doesn't exist or is not accessible/");
1429
1430 }
1431 }
1432 else
1433 {
1434 System.out.println("Network Interface for the specified address is not found");
1435 }
1436 }
1437 catch(UnknownHostException he)
1438 {
1439 }
1440 catch(SocketException e)
1441 {
1442 }
1443 }
1444}
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1456basics
1457Basic network commands
1458ping
1459The ping command (named after the sound of an active sonar system) sends echo requests to the host
1460specified on the command line, and lists the responses received.
1461$ ping ipAddress or hostname
1462e.g
1463$ ping www.vit.ac.in
1464• ping - sends an ICMP ECHO_REQUEST packet to the specified host. If the host responds, an
1465ICMP packet is received.
1466• One can “ping†an IP address to see if a machine is alive.
1467• It provides a very quick way to see if a machine is up and connected to the network.
1468netstat
1469• It works with the LINUX Network Subsystem, it will tell you what the status of ports are ie. open,
1470closed, waiting connections. It is used to display the TCP/IP network protocol statistics and
1471information.
1472tcpdump
1473This is a sniffer, a program that captures packets off a network interface and interprets them.
1474hostname
1475Tells the user the host name of the computer they are logged into.
1476traceroute
1477traceroute will show the route of a packet. It attempts to list the series of hosts through which your
1478packets travel on their way to a given destination.
1479Command syntax:
1480traceroute machine_name_or_ip
1481e.g traceroute www.vit.ac.in
1482Each host will be displayed, along with the response times at each host.
1483finger
1484Retrieves information about the specified user.
1485e.g finger bit50001
1486ifconfig ( In Windows use ipconfig )
1487This command is used to configure network interfaces, or to display their current configuration.
1488dig
1489The "domain information groper" tool. If you give a hostname as an argument to output information
1490about that host, including it's IP address, hostname and various other information.
1491e.g dig vitlinux
1492telnet
1493telnet allows you to log in to a computer, just as if you were sitting at the terminal. Once your
1494username and password are verified, you are given a shell prompt. From here, you can do anything
1495requiring a text console.
1496ftp
1497To connect to an FTP server use
1498ftp ipaddress
1499netstat
1500Displays contents of /proc/net files. It works with the LINUX Network Subsystem, it will tell
1501you what the status of ports are ie. open, closed, waiting, masquerade connections. It will also
1502display various other things. It has many different options.
1503tcpdump
1504This is a sniffer, a program that captures packets off a network interface and interprets them
1505for you. It understands all basic internet protocols, and can be used to save entire packets for
1506later inspection.
1507ping
1508The ping command (named after the sound of an active sonar system) sends echo requests to
1509the host you specify on the command line, and lists the responses received their round trip
1510time.
1511You simply use ping as:
1512ping ip_or_host_name
1513hostname
1514Tells the user the host name of the computer they are logged into. Note: may be called host.
1515traceroute
1516traceroute will show the route of a packet. It attempts to list the series of hosts through which
1517your packets travel on their way to a given destination. Also have a look at xtraceroute (one
1518of several graphical equivalents of this program).
1519Command syntax:
1520traceroute machine_name_or_ip
1521tracepath
1522tracepath performs a very simlar function to traceroute the main difference is that tracepath
1523doesn't take complicated options.
1524Command syntax:
1525tracepath machine_name_or_ip
1526findsmb
1527findsmb is used to list info about machines that respond to SMB name queries (for example
1528windows based machines sharing their hard disk's).
1529Command syntax:
1530Findsmb
1531This would find all machines possible, you may need to specify a particular subnet to query
1532those machines only...
1533nmap
1534“ network exploration tool and security scannerâ€. nmap is a very advanced network tool used
1535to query machines (local or remote) as to whether they are up and what ports are open on
1536these machines.
1537A simple usage example:
1538nmap machine_name
1539This would query your own machine as to what ports it keeps open. nmap is a very powerful
1540tool, documentation is available on the nmap site as well as the information in the manual
1541page.
1542telnet
1543Someone once stated that telnet(1) was the coolest thing he had ever seen on computers. The ability
1544to remotely log in and do stuff on another computer is what separates Unix and Unix-like operating
1545systems from other operating systems.
1546telnet allows you to log in to a computer, just as if you were sitting at the terminal. Once your
1547username and password are verified, you are given a shell prompt. From here, you can do anything
1548requiring a text console. Compose email, read newsgroups, move files around, and so on. If you are
1549running X and you telnet to another machine, you can run X programs on the remote computer and
1550display them on yours.
1551To login to a remote machine, use this syntax:
1552% telnet <hostname>
1553If the host responds, you will receive a login prompt. Give it your username and password. That's it.
1554You are now at a shell. To quit your telnet session, use either the exit command or the logout
1555command.
1556telnet does not encrypt the information it sends. Everything is sent in plain text, even passwords.
1557It is not advisable to use telnet over the Internet. Instead, consider the Secure Shell. It encrypts
1558all traffic and is available for free.
1559The other use of telnet
1560Now that we have convinced you not to use the telnet protocol anymore to log into a remote machine,
1561we'll show you a couple of useful ways to use telnet.
1562You can also use the telnet command to connect to a host on a certain port.
1563% telnet <hostname> [port]
1564This can be quite handy when you quickly need to test a certain service, and you need full control
1565over the commands, and you need to see what exactly is going on. You can interactively test or use
1566an SMTP server, a POP3 server, an HTTP server, etc. this way.
1567In the next figure you'll see how you can telnet to a HTTP server on port 80, and get some basic
1568information from it.
1569Figure 13-1. Telnetting to a webserver
1570% telnet store.slackware.com 80
1571Trying 69.50.233.153...
1572Connected to store.slackware.com.
1573Escape character is '^]'.
1574HEAD / HTTP/1.0
1575HTTP/1.1 200 OK
1576Date: Mon, 25 Apr 2005 20:47:01 GMT
1577Server: Apache/1.3.33 (Unix) mod_ssl/2.8.22 OpenSSL/0.9.7d
1578Last-Modified: Fri, 18 Apr 2003 10:58:54 GMT
1579ETag: "193424-c0-3e9fda6e"
1580Accept-Ranges: bytes
1581Content-Length: 192
1582Connection: close
1583Content-Type: text/html
1584Connection closed by foreign host.
1585%
15861-)arp :
1587When we need an Ethernet (MAC) address we can use arp(address resolution protocol).
1588In other words it shows the physical address of an host.
1589Example:
1590C:\Documents and Settings\sysadm>arp -a
1591Interface: 169.254.195.199 --- 0x2
1592Internet Address Physical Address Type
1593216.109.127.60 00-53-45-00-00-00 static
15942-)nslookup:
1595Displays information from Domain Name System (DNS) name servers.
1596Example:
1597C:\Documents and Settings\sysadm>nslookup itu.dk
1598Server: ns3.inet.tele.dk
1599Address: 193.162.153.164
1600Non-authoritative answer:
1601Name: itu.dk
1602Address: 130.226.133.2
1603NOTE :If you write the command as above it shows as default your pc's server name firstly.
1604C:\Documents and Settings\sysadm>nslookup mail.yahoo.com itu.dk
1605Server: superman.itu.dk
1606Address: 130.226.133.2
1607Non-authoritative answer:
1608Name: login.yahoo.akadns.net
1609Address: 216.109.127.60
1610Aliases: mail.yahoo.com, login.yahoo.com
1611NOTE:Remark that in the second example we do not see the default server name.
1612There are many nslookup with optional commands.To read them type nslookup and enter
1613then type help and enter.
16143-)finger:
1615Displays the information about a user on the system.
1616Example:
1617NOTE :I could not find out the name of the server that we log on (windows) at the school.
1618Sysadmin does not know that either:o)
1619But as an example I tried it on the our unix server.
1620[hilmiolgun@ssh hilmiolgun]$ finger
1621Login Name Tty Idle Login Time Office Office Phone
1622adel Adel Abu-Sharkh pts/1 7 Sep 10 00:11 (cpe.atm2-0-
16231091080.0x50a0bcb2.albnxx13.customer.tele.dk)
1624adel Adel Abu-Sharkh pts/2 9 Sep 9 23:56 (cpe.atm2-0-
16251091080.0x50a0bcb2.albnxx13.customer.tele.dk)
1626hilmiolgun Hilmi Olgun pts/9 Sep 10 00:20 (0x3ef3e2fe.albnxx8.adsl.tele.dk)
1627hm Hanne Munkholm pts/6 1:56 Sep 8 21:27 (off180.palombia.dk)
1628jcg Jens Christian Godsk pts/4 1d Sep 8 10:28 (toscana.itu.dk)
1629kaj Kenneth Ahn Jensen pts/7 Sep 10 00:11 (cpe.atm2-0-
163054493.0x50a4ad32.boanxx12.customer.tele.dk)
1631root root pts/8 1 Sep 10 00:12 (sysadm2.itu.dk)
1632troels Troels Arvin pts/5 3:49 Sep 9 20:31 (62.79.119.132.adsl.vbr.worldonline.dk)
1633webclaus Claus Bech Rasmussen pts/0 6 Sep 10 00:11 (port967.ds1-khk.adsl.cybercity.dk)
1634NOTE :What I did is :I first check the online users,and get a list of them(above).
1635Then i just choosed one user to get information about him(below)
1636[hilmiolgun@ssh hilmiolgun]$ finger hm
1637Login: hm Name: Hanne Munkholm
1638Directory: /import/home/hm Shell: /bin/bash
1639On since Mon Sep 8 21:27 (CEST) on pts/6 from off180.palombia.dk
16401 hour 56 minutes idle
1641Last login Tue Sep 9 11:05 (CEST) on pts/12 from stud127.itu.dk
1642New mail received Mon Nov 11 23:01 2002 (CET)
1643Unread since Sat Oct 5 00:00 2002 (CEST)
1644Plan:
1645World Domination... fast.
1646[hilmiolgun@ssh hilmiolgun]$
16474-)ping:
1648Simpy shows if the remote machine is available or not....
1649Example:
1650C:\Documents and Settings\sysadm>ping webmail.itu.dk
1651Pinging tarzan.itu.dk [130.226.133.3] with 32 bytes of data:
1652Reply from 130.226.133.3: bytes=32 time=29ms TTL=55
1653Reply from 130.226.133.3: bytes=32 time=30ms TTL=55
1654Reply from 130.226.133.3: bytes=32 time=30ms TTL=55
1655Reply from 130.226.133.3: bytes=32 time=30ms TTL=55
1656Ping statistics for 130.226.133.3:
1657Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
1658Approximate round trip times in milli-seconds:
1659Minimum = 29ms, Maximum = 30ms, Average = 29ms
1660NOTE :Remark that the remote machine is replying.Otherwise the output will be "Request time out"
1661which means the
1662remote machine is not working well.(Not answering)
16635-)tracert:
1664It simply shows the path between source and destination address.
1665Example:
1666C:\Documents and Settings\sysadm>tracert webmail.itu.dk
1667Tracing route to tarzan.itu.dk [130.226.133.3]
1668over a maximum of 30 hops:
16691 * * * Request timed out.
16702 29 ms 19 ms 29 ms ge-0-2-1-2.1000M.albnxu1.ip.tele.dk [195.249.1.2 9]
16713 29 ms 29 ms 19 ms pos1-0.622M.lynxg1.ip.tele.dk [195.249.2.46]
16724 29 ms 19 ms 29 ms herman.fsknet.lyngby.forskningsnettet.dk [192.38 .7.1]
16735 29 ms 29 ms 19 ms 130.225.244.214
16746 29 ms 29 ms 29 ms 1.ku.forskningsnettet.dk [130.225.245.90]
16757 29 ms 29 ms 29 ms rk.itu.forskningsnettet.dk [130.226.249.30]
16768 29 ms 29 ms 29 ms 130.225.245.86
16779 29 ms 29 ms 29 ms tarzan.itu.dk [130.226.133.3]
1678Trace complete.
16796-)ftp:
1680For file transferring..(File transfer protocol)
1681Example:Lets you dont have an ftp software and you want to get a file from your school harddisk.
1682So to do that:
1683C:\Documents and Settings\sysadm>ftp
1684ftp> open
1685To ftp.itu.dk
1686Connected to ssh.itu.dk.
1687220 ProFTPD 1.2.8rc2 Server (ProFTPD Default Installation) [ssh.it-c.dk]
1688NOTE:What am I doing is simply:typing them one-by-one(after each typing remember to enter)
1689ftp,open,ftp.itu.dk
1690User (ssh.itu.dk:(none)): hilmiolgun
1691331 Password required for hilmiolgun.
1692Password:
1693230 User hilmiolgun logged in.
1694NOTE:The server will require username and password..
1695ftp> help
1696Commands may be abbreviated. Commands are:
1697! delete literal prompt send
1698? debug ls put status
1699append dir mdelete pwd trace
1700ascii disconnect mdir quit type
1701bell get mget quote user
1702binary glob mkdir recv verbose
1703bye hash mls remotehelp
1704cd help mput rename
1705close lcd open rmdir
1706ftp> help dir
1707dir List contents of remote directory
1708NOTE: If it is your first time to those commands just type help and get the commands.If you dont
1709know how to use
1710them type help commandname..
1711ftp> dir
1712200 PORT command successful
1713150 Opening ASCII mode data connection for file list
1714drwx------ 4 hilmiolgun hilmiolgun 155 Jul 1 14:02 Desktop
1715drwx------ 2 hilmiolgun hilmiolgun 4096 May 30 10:21 Mail
1716drwxr-xr-x 5 hilmiolgun hilmiolgun 90 Sep 2 02:59 MobilePositionSDK
1717drwx------ 7 hilmiolgun hilmiolgun 4096 Aug 8 2002 NTnetscape
1718drwxr--r-- 13 hilmiolgun hilmiolgun 4096 Sep 4 01:56 New Folder
1719-rw-rw-r-- 1 hilmiolgun hilmiolgun 74 Sep 9 12:56 TTI409B
1720drwx------ 2 hilmiolgun hilmiolgun 6 Jan 21 2002 cgi-bin
1721-rw-rw-r-- 1 hilmiolgun hilmiolgun 74 Sep 9 12:56 geu
1722-rw-rw-r-- 1 hilmiolgun hilmiolgun 74 Sep 9 12:56 hilmiolgun
1723drwxr-xr-x 6 hilmiolgun hilmiolgun 4096 Aug 14 15:59 image
1724drwxr-xr-x 3 hilmiolgun hilmiolgun 4096 Jul 29 16:03 jmf20-apidocs
1725drwxr-xr-x 4 hilmiolgun hilmiolgun 4096 Sep 9 14:10 NOTEsieee
1726drwx------ 2 hilmiolgun hilmiolgun 6 Feb 21 2002 nsmail
1727drwx------ 3 hilmiolgun hilmiolgun 103 Feb 21 2002 office52
1728drwx------ 2 hilmiolgun hilmiolgun 6 Jan 21 2002 private
1729drwxr--rwx 2 hilmiolgun hilmiolgun 4096 Aug 23 12:02 public_html
1730drwxr-xr-x 5 hilmiolgun hilmiolgun 4096 Sep 6 03:30 speech
1731-rw-rw-r-- 1 hilmiolgun hilmiolgun 2630 Sep 9 13:58 test.txt
1732-rw-rw-r-- 1 hilmiolgun hilmiolgun 148 Sep 9 14:03 testing.txt
1733226 Transfer complete.
1734ftp: 1318 bytes received in 0,24Seconds 5,49Kbytes/sec.
1735ftp> get testing.txt
1736200 PORT command successful
1737150 Opening ASCII mode data connection for testing.txt (148 bytes)
1738226 Transfer complete.
1739ftp: 161 bytes received in 0,02Seconds 8,05Kbytes/sec.
1740NOTE :After taking a look to the school harddisk ,I copied a file "testing.txt" to my local harddisk....
1741ftp> !dir
1742Volume in drive C has no label.
1743Volume Serial Number is 0868-D52D
1744Directory of C:\Documents and Settings\sysadm
174510-09-2003 00:21 <DIR> .
174610-09-2003 00:21 <DIR> ..
174731-08-2003 07:28 <DIR> .java
174825-04-2003 12:18 <DIR> .javaws
174923-04-2003 15:26 <DIR> .jpi_cache
175026-08-2003 04:59 <DIR> .Nokia
175107-09-2003 01:46 12.546 .plugin140_03.trace
175207-09-2003 04:46 693 .plugin141_02.trace
175307-09-2003 01:20 164 .saves-3824-IBMR31IMAGE
175407-09-2003 01:20 <DIR> Desktop
175507-09-2003 08:05 <DIR> Favorites
175606-09-2003 05:29 80.140 love.wav
175709-09-2003 23:45 <DIR> mindterm
175809-09-2003 11:02 <DIR> My Documents
175910-09-2003 00:21 2.903 plugin131_08.trace
176025-04-2003 11:44 <DIR> Start Menu
176106-09-2003 21:21 <DIR> studio5se_user
176206-09-2003 05:32 18 test.txt
176306-09-2003 05:20 70 testing
176410-09-2003 00:37 161 testing.txt
176526-08-2003 03:46 <DIR> WINDOWS
17668 File(s) 96.695 bytes
176713 Dir(s) 3.842.056.192 bytes free
1768ftp> send love.wav
1769200 PORT command successful
1770150 Opening ASCII mode data connection for love.wav
1771226 Transfer complete.
1772ftp: 80140 bytes sent in 3,97Seconds 20,21Kbytes/sec.
1773ftp> dir
1774200 PORT command successful
1775150 Opening ASCII mode data connection for file list
1776drwx------ 4 hilmiolgun hilmiolgun 155 Jul 1 14:02 Desktop
1777drwx------ 2 hilmiolgun hilmiolgun 4096 May 30 10:21 Mail
1778drwxr-xr-x 5 hilmiolgun hilmiolgun 90 Sep 2 02:59 MobilePositionSDK
1779drwx------ 7 hilmiolgun hilmiolgun 4096 Aug 8 2002 NTnetscape
1780drwxr--r-- 13 hilmiolgun hilmiolgun 4096 Sep 4 01:56 New Folder
1781-rw-rw-r-- 1 hilmiolgun hilmiolgun 74 Sep 9 12:56 TTI409B
1782drwx------ 2 hilmiolgun hilmiolgun 6 Jan 21 2002 cgi-bin
1783-rw-rw-r-- 1 hilmiolgun hilmiolgun 74 Sep 9 12:56 geu
1784-rw-rw-r-- 1 hilmiolgun hilmiolgun 74 Sep 9 12:56 hilmiolgun
1785drwxr-xr-x 6 hilmiolgun hilmiolgun 4096 Aug 14 15:59 image
1786drwxr-xr-x 3 hilmiolgun hilmiolgun 4096 Jul 29 16:03 jmf20-apidocs
1787-rw-rw-r-- 1 hilmiolgun hilmiolgun 80137 Sep 9 22:36 love.wav
1788drwxr-xr-x 4 hilmiolgun hilmiolgun 4096 Sep 9 14:10 NOTEsieee
1789drwx------ 2 hilmiolgun hilmiolgun 6 Feb 21 2002 nsmail
1790drwx------ 3 hilmiolgun hilmiolgun 103 Feb 21 2002 office52
1791drwx------ 2 hilmiolgun hilmiolgun 6 Jan 21 2002 private
1792drwxr--rwx 2 hilmiolgun hilmiolgun 4096 Aug 23 12:02 public_html
1793drwxr-xr-x 5 hilmiolgun hilmiolgun 4096 Sep 6 03:30 speech
1794-rw-rw-r-- 1 hilmiolgun hilmiolgun 2630 Sep 9 13:58 test.txt
1795-rw-rw-r-- 1 hilmiolgun hilmiolgun 148 Sep 9 14:03 testing.txt
1796226 Transfer complete.
1797ftp: 1387 bytes received in 0,07Seconds 19,81Kbytes/sec.
1798ftp>
1799NOTE:At the end first looking at the local working directory and sending a file "love.wav" to the
1800school harddisk.
18017-)net:
1802It has many options,which are for checking/starting/stopping nt
1803services,users,messaging,configuration and so on...
1804Some of those options require administration privileges..
1805Example:
1806NOTE: To have an overview of commands options....
1807C:\Documents and Settings\sysadm>net
1808The syntax of this command is:
1809NET COMMANDS
1810NET [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP |
1811HELPMSG | LOCALGROUP | NAME | PAUSE | PRINT | SEND | SESSION |
1812SHARE | START | STATISTICS | STOP | TIME | USE | USER | VIEW ]
1813NOTE: And furthermore to get an overview of a specific option ...
1814C:\Documents and Settings\sysadm>net help print
1815The syntax of this command is:
1816NET PRINT
1817\\computername\sharename
1818[\\computername] job# [/HOLD | /RELEASE | /DELETE]
1819NET PRINT displays print jobs and shared queues.
1820For each queue, the display lists jobs, showing the size
1821and status of each job, and the status of the queue.
1822\\computername Is the name of the computer sharing the printer
1823queue(s).
1824sharename Is the name of the shared printer queue.
1825job# Is the identification number assigned to a print
1826job. A computer with one or more printer queues
1827assigns each print job a unique number.
1828/HOLD Prevents a job in a queue from printing.
1829The job stays in the printer queue, and other
1830jobs bypass it until it is released.
1831/RELEASE Reactivates a job that is held.
1832/DELETE Removes a job from a queue.
1833NET HELP command | MORE displays Help one screen at a time.
1834Finally in addition to above there are also those commands: hostname ,lpq, lpr ,rsh ,tftp ,nbstat
1835,netstat.
1836To get familiar with those commands simply type commandname /? at the command line.
1837C:\>net
1838The syntax of this command is:
1839NET [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP |
1840HELPMSG | LOCALGROUP | NAME | PAUSE | PRINT | SEND | SESSION |
1841SHARE | START | STATISTICS | STOP | TIME | USE | USER | VIEW ]
1842C:\>net use
1843New connections will not be remembered.
1844Status Local Remote Network
1845-------------------------------------------------------------------------------
1846OK F: \\cse-sec\fac Microsoft Windows Network
1847C:\>net user
1848User accounts for \\CSE-DEPT-05
1849-------------------------------------------------------------------------------
1850Administrator Guest
1851C:\>net statistics
1852Statistics are available for the following running services:
1853Server
1854Workstation
1855Displays protocol statistics and current TCP/IP network connections.
1856NETSTAT [-a] [-e] [-n] [-s] [-p proto] [-r] [interval]
1857-a Displays all connections and listening ports.
1858-e Displays Ethernet statistics. This may be combined with the
1859-s option.
1860-n Displays addresses and port numbers in numerical form.
1861-p proto Shows connections for the protocol specified by proto; proto
1862may be TCP or UDP. If used with the -s option to display
1863per-protocol statistics, proto may be TCP, UDP, or IP.
1864-r Displays the routing table.
1865-s Displays per-protocol statistics. By default, statistics
1866are shown for TCP, UDP and IP; the -p option may be used
1867to specify a subset of the default.
1868interval Redisplays selected statistics, pausing interval seconds
1869between each display. Press CTRL+C to stop redisplaying
1870statistics. If omitted, netstat will print the current
1871configuration information once.
1872C:\>net name
1873Name
1874-------------------------------------------------------------------------------
1875CSE-DEPT-05
1876C:\>net session
1877Computer User name Client Type Opens Idle time
1878-------------------------------------------------------------------------------
1879\\ENGLISH-03 Windows NT 1381 0 00:10:47
1880\\ENGLISHBDC Windows NT 1381 0 00:02:01
1881C:\>net accounts
1882Force user logoff how long after time expires?: Never
1883Minimum password age (days): 0
1884Maximum password age (days): 42
1885Minimum password length: 0
1886Length of password history maintained: None
1887Lockout threshold: Never
1888Lockout duration (minutes): 30
1889Lockout observation window (minutes): 30
1890Computer role: WORKSTATION
1891C:\>net localgroup
1892Aliases for \\CSE-DEPT-05
1893-------------------------------------------------------------------------------
1894*Administrators *Backup Operators *Guests
1895*Power Users *Replicator *Users
1896C:\>net config server
1897Server Name \\CSE-DEPT-05
1898Server Comment
1899Software version Windows NT 4.0
1900Server is active on NetBT_DLKRTS1 (0050ba8b326b) NetBT_DLKRTS1
1901(0050ba8b326b) NwlnkIpx (0050ba8b326b) NwlnkNb (0050ba8b326b) Nbf_DLKRTS1 (0050
1902ba8b326b)
1903Server hidden No
1904Maximum Logged On Users 10
1905Maximum open files per session 2048
1906Idle session time (min) 15
1907C:\>net config workstation
1908Computer name \\CSE-DEPT-05
1909User name Administrator
1910Workstation active on NwlnkNb (0050BA8B326B) NetBT_DLKRTS1 (0050B
1911A8B326B) Nbf_DLKRTS1 (0050BA8B326B)
1912Software version Windows NT 4.0
1913Workstation domain WORKGROUP
1914Logon domain CSE-DEPT-05
1915COM Open Timeout (sec) 3600
1916COM Send Count (byte) 16
1917COM Send Timeout (msec) 250
1918C:\>net share
1919Share name Resource Remark
1920-------------------------------------------------------------------------------
1921D$ D:\ Default share
1922IPC$ Remote IPC
1923C$ C:\ Default share
1924ADMIN$ C:\WINNT Remote Admin
1925E$ E:\ Default share
1926abishek E:\abishek
1927akshu E:\akshu
1928HARSHINI D:\ HARSHINI
1929DHARSHINI E:\ DHARSHINI
1930C:\>net stop messenger
1931The Messenger service is stopping.
1932The Messenger service was stopped successfully.
1933C:\>net start messenger
1934The Messenger service is starting...
1935The Messenger service was started successfully.
1936Network Configuration commands
1937ifconfig
1938This command is used to configure network interfaces, or to display their current
1939configuration. In addition to activating and deactivating interfaces with the “up†and “downâ€
1940settings, this command is necessary for setting an interface's address information if you don't
1941have the ifcfg script.
1942Use ifconfig as either:
1943ifconfig
1944This will simply list all information on all network devices currently up.
1945ifconfig eth0 down
1946This will take eth0 (assuming the device exists) down, it won't be able to receive or send
1947anything until you put the device back “up†again.
1948Clearly there are a lot more options for this tool, you will need to read the manual/info page to
1949learn more about them.
1950ifup
1951Use ifup device-name to bring an interface up by following a script (which will contain your
1952default networking settings). Simply type ifup and you will get help on using the script.
1953For example typing:
1954ifup eth0
1955Will bring eth0 up if it is currently down.
1956ifdown
1957Use ifdown device-name to bring an interface down using a script (which will contain your
1958default network settings). Simply type ifdown and you will get help on using the script.
1959For example typing:
1960ifdown eth0
1961Will bring eth0 down if it is currently up.
1962ifcfg
1963Use ifcfg to configure a particular interface. Simply type ifcfg to get help on using this script.
1964For example, to change eth0 from 192.168.0.1 to 192.168.0.2 you could do:
1965ifcfg eth0 del 192.168.0.1
1966ifcfg eth0 add 192.168.0.2
1967The first command takes eth0 down and removes that stored IP address and the second one
1968brings it back up with the new address.
1969route
1970The route command is the tool used to display or modify the routing table. To add a gateway
1971as the default you would type:
1972route add default gw some_computer
1973INTERNET SPECIFIC COMMANDS
1974host
1975Performs a simple lookup of an internet address (using the Domain Name System, DNS).
1976Simply type:
1977host ip_address
1978or
1979host domain_name
1980dig
1981The "domain information groper" tool. More advanced then host... If you give a hostname as
1982an argument to output information about that host, including it's IP address, hostname and
1983various other information.
1984For example, to look up information about “www.amazon.com†type:
1985dig www.amazon.com
1986To find the host name for a given IP address (ie a reverse lookup), use dig with the `-x' option.
1987dig -x 100.42.30.95
1988This will look up the address (which may or may not exist) and returns the address of the
1989host, for example if that was the address of “http://slashdot.org†then it would return
1990“http://slashdot.orgâ€.
1991dig takes a huge number of options (at the point of being too many), refer to the manual page
1992for more information.
1993whois
1994(now BW whois) is used to look up the contact information from the “whois†databases, the
1995servers are only likely to hold major sites. Note that contact information is likely to be hidden
1996or restricted as it is often abused by crackers and others looking for a way to cause malicious
1997damage to organisation's.
1998wget
1999(GNU Web get) used to download files from the World Wide Web.
2000To archive a single web-site, use the -m or --mirror (mirror) option.
2001Use the -nc (no clobber) option to stop wget from overwriting a file if you already have it.
2002Use the -c or --continue option to continue a file that was unfinished by wget or another
2003program.
2004Simple usage example:
2005wget url_for_file
2006This would simply get a file from a site.
2007wget can also retrieve multiple files using standard wildcards, the same as the type used in
2008bash, like *, [ ], ?. Simply use wget as per normal but use single quotation marks (' ') on the
2009URL to prevent bash from expanding the wildcards. There are complications if you are
2010retrieving from a http site (see below...).
2011Advanced usage example, (used from wget manual page):
2012wget --spider --force-html -i bookmarks.html
2013This will parse the file bookmarks.html and check that all the links exist.
2014Advanced usage: this is how you can download multiple files using http (using a wildcard...).
2015Notes: http doesn't support downloading using standard wildcards, ftp does so you may use
2016wildcards with ftp and it will work fine. A work-around for this http limitation is shown
2017below:
2018wget -r -l1 --no-parent -A.gif http://www.website.com[1]
2019This will download (recursively), to a depth of one, in other words in the current directory and
2020not below that. This command will ignore references to the parent directory, and downloads
2021anything that ends in “.gifâ€. If you wanted to download say, anything that ends with “.pdf†as
2022well than add a -A.pdf before the website address. Simply change the website address and the
2023type of file being downloaded to download something else. Note that doing -A.gif is the same
2024as doing -A “*.gif†(double quotes only, single quotes will not work).
2025wget has many more options refer to the examples section of the manual page, this tool is very
2026well documented.
2027Alternative website downloaders: You may like to try alternatives like httrack. A full GUI
2028website downloader written in python and available for GNU/Linux
2029curl
2030curl is another remote downloader. This remote downloader is designed to work without user
2031interaction and supports a variety of protocols, can upload/download and has a large number
2032of tricks/work-arounds for various things. It can access dictionary servers (dict), ldap servers,
2033ftp, http, gopher, see the manual page for full details.
2034To access the full manual (which is huge) for this command type:
2035curl -M
2036For general usage you can use it like wget. You can also login using a user name by using the
2037-u option and typing your username and password like this:
2038curl -u username:password http://www.placetodownload/file
2039To upload using ftp you the -T option:
2040curl -T file_name ftp://ftp.uploadsite.com
2041To continue a file use the -C option:
2042curl -C - -o file http://www.site.com
2043View and modify network interfaces
2044ifconfig -a Show information about all network interfaces
2045ifconfig eth0 Show information only about the interface eth0
2046ifconfig eth0 up Bring up the interface eth0
2047ifconfig eth0 down Take down the interface eth0
2048Simple network diagnostic commands
2049ping hostname Send ICMP echo requests to the host hostname
2050traceroute hostname Trace the network path to hostname
2051View open network connections
2052netstat -a Show information about all open network connections
2053netstat -a | grep LISTEN Show information about all open network ports
2054Set/view routing information
2055netstat -r View system routing tables
2056route View system routing tables
2057The command route can also be used to add or delete routes. Examples:
2058route add -host 192.168.3.4 gw 192.168.3.1 netmask 255.255.0.0
2059route del -host 192.168.3.4
2060NETSTAT.exe TCP/IP Network Statistics
2061Displays protocol statistics and current TCP/IP network connections.
2062NETSTAT [-a] [-e] [-n] [-s] [-p proto] [-r] [interval]
2063-a Displays all connections and listening ports.
2064-e Displays Ethernet statistics. This may be combined with the -s option.
2065-n Displays addresses and port numbers in numerical form.
2066-p proto Shows connections for the protocol specified by proto; proto may be TCP or UDP.
2067If used with the -s option to display per-protocol statistics, proto may be TCP, UDP,
2068or IP.
2069-r Displays the routing table.
2070-s Displays per-protocol statistics. By default, statistics are shown for TCP, UDP and IP;
2071the -p option may be used to specify a subset of the default.
2072interval Redisplays selected statistics, pausing interval seconds between each display. Press
2073CTRL+C to stop redisplaying statistics. If omitted, netstat will print the current
2074configuration information once.
2075C:\WINDOWS>netstat -a
2076Active Connections
2077Proto Local Address Foreign Address State
2078TCP My_Comp:ftp localhost:0 LISTENING
2079TCP My_Comp:80 localhost:0 LISTENING
2080Or with the "-an" parameters:
2081C:\WINDOWS>netstat -an
2082Active Connections
2083Proto Local Address Foreign Address State
2084TCP 0.0.0.0:21 0.0.0.0:0 LISTENING
2085TCP 0.0.0.0:80 0.0.0.0:0 LISTENING
2086By simply opening a browser connection to both the HTTP (port 80) and FTP (port 21) servers
2087(while still offline!), I saw the following:
2088C:\WINDOWS>netstat -a
2089Active Connections
2090Proto Local Address Foreign Address State
2091TCP My_Comp:ftp localhost:0 LISTENING
2092TCP My_Comp:80 localhost:0 LISTENING
2093TCP My_Comp:1104 localhost:0 LISTENING
2094TCP My_Comp:ftp localhost:1104 ESTABLISHED
2095TCP My_Comp:1102 localhost:0 LISTENING
2096TCP My_Comp:1103 localhost:0 LISTENING
2097TCP My_Comp:80 localhost:1111 TIME_WAIT
2098TCP My_Comp:1104 localhost:ftp ESTABLISHED
2099TCP My_Comp:1107 localhost:0 LISTENING
2100TCP My_Comp:1112 localhost:80 TIME_WAIT
2101UDP My_Comp:1102 *:*
2102UDP My_Comp:1103 *:*
2103UDP My_Comp:1107 *:*
2104This may be a bit confusing to some people, but remember I'm running BOTH the servers and clients
2105on the same machine in these examples. A little later (using both 'a' and 'n') I got this:
2106C:\WINDOWS>netstat -an
2107Active Connections
2108Proto Local Address Foreign Address State
2109TCP 0.0.0.0:21 0.0.0.0:0 LISTENING
2110TCP 0.0.0.0:80 0.0.0.0:0 LISTENING
2111TCP 0.0.0.0:1104 0.0.0.0:0 LISTENING
2112TCP 127.0.0.1:21 127.0.0.1:1104 FIN_WAIT_2
2113TCP 127.0.0.1:1102 0.0.0.0:0 LISTENING
2114TCP 127.0.0.1:1103 0.0.0.0:0 LISTENING
2115TCP 127.0.0.1:1104 127.0.0.1:21 CLOSE_WAIT
2116TCP 127.0.0.1:1107 0.0.0.0:0 LISTENING
2117UDP 127.0.0.1:1102 *:*
2118UDP 127.0.0.1:1103 *:*
2119UDP 127.0.0.1:1107 *:*
2120After turning off my server, I ended up with this for a while:
2121C:\WINDOWS>netstat -an
2122Active Connections
2123Proto Local Address Foreign Address State
2124TCP 127.0.0.1:80 127.0.0.1:1150 TIME_WAIT
2125TCP 127.0.0.1:80 127.0.0.1:1151 TIME_WAIT
2126PING.exe
2127Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
2128[-r count] [-s count] [[-j host-list] | [-k host-list]]
2129[-w timeout] destination-list
2130Options:
2131-t Ping the specifed host until interrupted.
2132-a Resolve addresses to hostnames.
2133-n count Number of echo requests to send.
2134-l size Send buffer size.
2135-f Set "Don't Fragment" flag in packet.
2136-i TTL Time To Live.
2137-v TOS Type Of Service.
2138-r count Record route for count hops.
2139-s count Timestamp for count hops.
2140-j host-list Loose source route along host-list.
2141-k host-list Strict source route along host-list.
2142-w timeout Timeout in milliseconds to wait for each reply.
2143There's one special IP number everyone should know about:
2144127.0.0.1 - localhost (or loopback).
2145This is used to connect ( through a browser, for example) to a Web server on your own computer.
2146(127 being reserved for this purpose.) You can use this IP number at all times. It doesn't matter if
2147you're connected to the Internet or not.
2148It's also called the loopback address because you can ping it and get returns even when you're
2149offline (not connected to any network). If you don't get any valid replies, then there's a problem with
2150the computer's Network settings. Here's a typical response to the 'ping' command:
2151Here's another recent example using the name of my computer which I have tied to the IP number
2152127.0.0.1 in my C:\WINDOWS\HOSTS file:
2153C:\WINDOWS>ping My_Comp
2154Pinging My_Comp [127.0.0.1] with 32 bytes of data:
2155Reply from 127.0.0.1: bytes=32 time=1ms TTL=128
2156Reply from 127.0.0.1: bytes=32 time=1ms TTL=128
2157Reply from 127.0.0.1: bytes=32 time<10ms TTL=128
2158Reply from 127.0.0.1: bytes=32 time=1ms TTL=128
2159Ping statistics for 127.0.0.1:
2160Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
2161Approximate round trip times in milli-seconds:
2162Minimum = 0ms, Maximum = 1ms, Average = 0ms
2163TRACERT.exe Trace Route
2164Usage:
2165tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name
2166Options:
2167-d Do not resolve addresses to hostnames.
2168-h maximum_hops Maximum number of hops to search for target.
2169-j host-list Loose source route along host-list.
2170-w timeout Wait timeout milliseconds for each reply.
2171Here's an example which traces the route from some ISP in Los Angeles to the main server at UCLA
2172in California ( note how two computers relatively close to each other may be routed way round
2173about! ):
2174C:\WINDOWS>tracert www.ucla.edu
2175Tracing route to www.ucla.edu [169.232.33.129]
2176over a maximum of 30 hops:
21771 141 ms 132 ms 140 ms wla-ca-pm6.icg.net [165.236.29.85]
21782 134 ms 131 ms 139 ms whv-ca-gw1.icg.net [165.236.29.65]
21793 157 ms 132 ms 143 ms f3-1-0.lai-ca-gw1.icg.net [165.236.24.89]
21804 194 ms 193 ms 188 ms a0-0-0-1.dai-tx-gw1.icg.net [163.179.235.61]
21815 300 ms 211 ms 214 ms a1-1-0-1.ati-ga-gw1.icg.net [163.179.235.186]
21826 236 ms 237 ms 247 ms a5-0-0-1.was-dc-gw1.icg.net [163.179.235.129]
21837 258 ms 236 ms 244 ms 163.179.243.205
21848 231 ms 233 ms 230 ms wdc-brdr-03.inet.qwest.net [205.171.4.153]
21859 240 ms 230 ms 236 ms wdc-core-03.inet.qwest.net [205.171.24.69]
218610 262 ms 264 ms 263 ms hou-core-01.inet.qwest.net [205.171.5.187]
218711 281 ms 263 ms 259 ms hou-core-03.inet.qwest.net [205.171.23.9]
218812 272 ms 229 ms 222 ms lax-core-02.inet.qwest.net [205.171.5.163]
218913 230 ms 217 ms 230 ms lax-edge-07.inet.qwest.net [205.171.19.58]
219014 228 ms 219 ms 220 ms 63-145-160-42.cust.qwest.net [63.145.160.42]
219115 218 ms 222 ms 218 ms ISI-7507--ISI.POS.calren2.net [198.32.248.21]
219216 232 ms 222 ms 214 ms UCLA--ISI.POS.calren2.net [198.32.248.30]
219317 234 ms 226 ms 226 ms cbn5-gsr.calren2.ucla.edu [169.232.1.18]
219418 245 ms 227 ms 235 ms www.ucla.edu [169.232.33.129]
2195Trace complete.
2196Net Bios Stats
2197NBTSTAT.exe
2198Displays protocol statistics and current TCP/IP connections using NBT
2199(NetBIOS over TCP/IP).
2200NBTSTAT [-a RemoteName] [-A IP address] [-c] [-n] [-r] [-R] [-s] [S] [interval]
2201-a (adapter status) Lists the remote machine's name table given its name.
2202-A (Adapter status) Lists the remote machine's name table given its IP address.
2203-c (cache) Lists the remote name cache including the IP addresses.
2204-n (names) Lists local NetBIOS names.
2205-r (resolved) Lists names resolved by broadcast and via WINS
2206-R (Reload) Purges and reloads the remote cache name table
2207-S (Sessions) Lists sessions table with the destination IP addresses.
2208-s (sessions) Lists sessions table converting destination IP addresses to host names via the
2209hosts file.
2210RemoteName Remote host machine name.
2211IP address Dotted decimal representation of the IP address.
2212interval Redisplays selected statistics, pausing interval seconds between each display. Press
2213Ctrl+C to stop redisplaying statistics.
2214ROUTE.exe
2215Manipulates network routing tables.
2216ROUTE [-f] [command [destination] [MASK netmask] [gateway]]
2217-f Clears the routing tables of all gateway entries. If this is used in conjunction
2218with one of the commands, the tables are cleared prior to running the command.
2219command Specifies one of four commands
2220PRINT Prints a route
2221ADD Adds a route
2222DELETE Deletes a route
2223CHANGE Modifies an existing route
2224destination Specifies the host to send command.
2225MASK If the MASK keyword is present, the next parameter is interpreted as the
2226netmask parameter.
2227netmask If provided, specifies a sub-net mask value to be associated with this route entry.
2228If not specified, if defaults to 255.255.255.255.
2229gateway Specifies gateway.
2230All symbolic names used for destination or gateway are looked up in the network and host
2231name database files NETWORKS and HOSTS, respectively.
2232If the command is print or delete, wildcards may be used for the destination and gateway, or
2233the gateway argument may be omitted.
2234ARP.exe Address Resolution Protocol
2235ARP -s inet_addr eth_addr [if_addr]
2236ARP -d inet_addr [if_addr]
2237ARP -a [inet_addr] [-N if_addr]
2238-a Displays current ARP entries by interrogating the current protocol data. If inet_addr
2239is specified, the IP and Physical addresses for only the specified computer are
2240displayed. If more than one network interface uses ARP, entries for each ARP
2241table are displayed.
2242-g (Same as -a)
2243inet_addr Specifies an internet address.
2244-N if_addr Displays the ARP entries for the network interface specified by if_addr.
2245-d Deletes the host specified by inet_addr.
2246-s Adds the host and associates the Internet address inet_addr with the Physical address
2247eth_addr. The Physical address is given as 6 hexadecimal bytes separated by hyphens.
2248The entry is permanent.
2249eth_addr Specifies a physical address.
2250if_addr If present, this specifies the Internet address of the interface
2251whose address translation table should be modified. If not present, the first
2252applicable interface will be used.