Sinisterly
JScan - simple java port scanner - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Java, JVM, & JRE (https://sinister.li/Forum-Java-JVM-JRE)
+--- Thread: JScan - simple java port scanner (/Thread-JScan-simple-java-port-scanner)



JScan - simple java port scanner - Dreamwalker - 08-15-2013

Code:
import java.net.*; import java.io.IOException; import java.util.Scanner; public class JScan implements Runnable { public static void main(String[] args) { new JScan(); } public JScan(){ new Thread(this).start(); } public void run() { String host; int start_port, end_port; Scanner input = new Scanner(System.in); System.out.println("_________________________________"); System.out.println("Port Scanner coded by DreamWalker"); System.out.println(" "); System.out.println("_________________________________\n"); System.out.print("Target host or IP?: "); host = input.nextLine(); System.out.print("Start port?: "); start_port = input.nextInt(); System.out.print("End port?: "); end_port = input.nextInt(); System.out.println("________________________________\nScanning...\n"); for (int current_port = start_port; current_port <= end_port; current_port++) try { Socket socket = new Socket(); socket.bind(null); socket.connect(new InetSocketAddress(host, current_port), 250); socket.close(); if(current_port == 21) System.out.println("FTP is open "+current_port); else if(current_port == 22) System.out.println("SSH is open "+current_port); else if(current_port == 23) System.out.println("Telnet is open "+current_port); else if(current_port == 25) System.out.println("SMTP is open "+current_port); else if(current_port == 80) System.out.println("HTTP is open "+current_port); else if(current_port == 110) System.out.println("POP3 is open "+current_port); else if(current_port == 143) System.out.println("IMAP is open "+current_port); else if(current_port == 443) System.out.println("SSL/HTTPS is open "+current_port); else if(current_port == 3389) System.out.println("RDP is open "+current_port); else if(current_port == 5900) System.out.println("VNC is open "+current_port); else System.out.println("Port open "+current_port); } catch (IOException ex) {} System.out.println("_________________________________\nFinished, please close."); try { System.in.read(); } catch (IOException e) { e.printStackTrace(); } } }



RE: JScan - simple java port scanner - Deque - 08-16-2013

Adhere to the Java coding conventions: Take care for proper intendation, put each statement on a new line, use correct variable names:

this_is_not_a_java_variable
butThisIs

Use a map for the port-to-name mappings or at least a switch case statement, which looks much cleaner than an if-else-if-... construction.

Why do you use a thread?


RE: JScan - simple java port scanner - Dreamwalker - 08-16-2013

(08-16-2013, 12:59 PM)Deque Wrote: Adhere to the Java coding conventions: Take care for proper intendation, put each statement on a new line, use correct variable names:

this_is_not_a_java_variable
butThisIs

Use a map for the port-to-name mappings or at least a switch case statement, which looks much cleaner than an if-else-if-... construction.

Why do you use a thread?

It's something I wrote in 5 mins and is sufficient for what I needed... and the extra thread was to create a seperate stack memory on the scan for stability and speed.


RE: JScan - simple java port scanner - Deque - 08-16-2013

(08-16-2013, 06:32 PM)Dreamwalker Wrote:
(08-16-2013, 12:59 PM)Deque Wrote: Adhere to the Java coding conventions: Take care for proper intendation, put each statement on a new line, use correct variable names:

this_is_not_a_java_variable
butThisIs

Use a map for the port-to-name mappings or at least a switch case statement, which looks much cleaner than an if-else-if-... construction.

Why do you use a thread?

It's something I wrote in 5 mins and is sufficient for what I needed... and the extra thread was to create a seperate stack memory on the scan for stability and speed.

Well, you published it.
Also the conventions are something you should make a habit of, so you don't even have to think about them, 5 minutes or not.
Using a single thread for stability and speed doesn't make sense at all. If you used several threads it would probably be of some use for the speed, but not like this.


RE: JScan - simple java port scanner - Ex094 - 08-17-2013

You should really consider posting in some working screen shots of your program