Unavailable Port Scanning using Java - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

Unavailable Port Scanning using Java

Share This
PortScanner.java
import java.io.IOException; import java.net.Socket; import java.net.UnknownHostException; public class PortScanner { public static void main(String[] args) { String host = "localhost"; if (args.length > 0) { host = args[0]; } for (int i = 1; i < 1024; i++) { try { Socket s = new Socket(host, i); System.out.println("There is a server on port " + i + " of " + host); s.close(); } catch (UnknownHostException e) { System.err.println(e); break; } catch (IOException e) { } } } }

PortScanner.java
import java.net.DatagramSocket; import java.net.SocketException; public class PortScanner { public static void main(String[] args) { for (int port = 1024; port <= 65535; port++) { try { DatagramSocket server = new DatagramSocket(port); server.close(); } catch (SocketException e) { System.out.println("There is a server on port " + port + "."); } } } }


Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.