esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

How do I connect to the daytime port (13)?
The daytime port 13 will return a datagram containing the server time.
On many systems, this port is being disabled, fearing hackers may use it to perform a denial-of-service attack of some sort. Based on the date format that the server returns, the hacker may also find out about the operating system.

Just open a socket and read a line. It will contain the server time if the port is enabled.
DaytimeClient.java:


import java.util.*;
import java.net.*;
import java.io.*;

public class DaytimeClient {
public static void main(String args[]) {
if (args.length != 1) {
System.out.println("java DaytimeClient <server>");
System.exit(1);
}

try {
Socket socket = new Socket(args[0], 13); // 7 is echo port
BufferedReader br = new BufferedReader(
new InputStreamReader(socket.getInputStream()));

String ret = br.readLine();
System.out.println(ret);

socket.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
}




Further Information
Author of answer: Joris Van den Bogaert

Comments to this answer are only viewable by members. Login or become a member!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.