|
Java™ by example!
|
|
|
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!
|
|
|
|
|