This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Hello can someone please elaborate a bit more on what exactly I have to do to receive the I/O exception. I am trying to code a UDP port scanner in Java as well, know how to send a datagrampacket but don't know what to do with it after that. Here's my code: *********************** InetAddress addy = InetAddress.getByName("184.108.40.206"); String text = "My first UDP Packet"; byte message = text.getBytes(); int port = 20; DatagramPacket dp = new DatagramPacket(message, message.length, addy, port); DatagramSocket sender = new DatagramSocket(); sender.send(dp); /*now no matter if the port is closed or open my client just hangs. How exactly do i get this I/O exception message if the port is closed?*/ dp = new DatagramPacket(message,message.length); sender.receive(dp); String received = new String(dp.getData(), 0); System.out.println("Received: " + received); sender.close(); ****************************** I cannot find the book titled "networking in java" on amazon or anywhere. Are you sure this is the right title? Can you please paste the example code in it regarding this UDP port scan? Thank you. Bo [ February 17, 2003: Message edited by: Bo Lin ]
Hi Ravi, Scanning UDP ports in a world full of firewalls and packet filtering software is to say the least a difficult task. First off, UDP does not guarantee delivery. Next, if the host you wish to scan is blocking ICMP destination unreachable and ICMP admin prohibited (and probably all ICMP packets) then the natural assumptions is that the port is open. That is exactly the way the popular port scanner nmap does UDP scanning and many times the assumption is wrong. Here is an excerpt from the javadocs for DatagramSocket.connect() alluding to this: If the remote destination to which the socket is connected does not exist, or is otherwise unreachable, and if an ICMP destination unreachable packet has been received for that address, then a subsequent call to send or receive may throw a PortUnreachableException. Note, there is no guarantee that the exception will be thrown. Hope this helps, Michael Morris
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher