aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes UDP Port Sacn Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "UDP Port Sacn" Watch "UDP Port Sacn" New topic
Author

UDP Port Sacn

ravi inguva
Ranch Hand

Joined: Feb 07, 2002
Posts: 34
how to achive UDP port scan using java??
i mean to say what all are the ways to find the UPD ports active on a particular host...
Thanks and regards


Sun Certified Java2 Programmer
aditya mahajan
Greenhorn

Joined: Jul 13, 2001
Posts: 8
Send a message to a particular port. If you do not receive an I/O Exception then the port is alive otherwise not. The complete example is given in the book Netwoking in Java
Bo Lin
Greenhorn

Joined: Nov 17, 2002
Posts: 6
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("111.111.111.111");
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 ]
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: UDP Port Sacn