Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Development
openScan [Java]
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="treebeard" data-source="post: 433316" data-attributes="member: 79259"><p>Greetings,</p><p></p><p>openScan is an open source port scanner that I am making in Java, for practice as well as a medium to further my own knowledge. This is a very early release and is only a crude version with minimal features. I'm working through some of the main features and methods in a single class and then I'm going to start from the beginning and structure the project in a more proper OOP style. When I get some more work done I'll post a link to the Github repo in case anyone is interested enough to keep up with it.</p><p></p><p><a href="https://pastebin.com/CcB98b8D" target="_blank">Link to pastebin</a></p><p></p><p>I hope you enjoy, thanks ^.^</p><p></p><p style="text-align: center">********** openScan is for educational purposes only and I'm in no way responsible for the misuse or misconduct of any individual who chooses to break rules **********</p><p></p><p>[SPOILER="Original Design of Features"]</p><p>[CODE=java]// Created by: Justin T</p><p></p><p>// Date: April 28, 2018</p><p></p><p>// Useful Information: Created using JDK 8 in IntelliJ IDEA.</p><p></p><p>// Purpose: Simple port scanner capable of reading an IPv4 address, starting port, and ending port.</p><p></p><p>// Will print a message if the port is open.</p><p></p><p>// In Progress: Threading, IPv6 support, Search by domain name, Intervals of ports to scan, Designing simple GUI,</p><p></p><p>// Display common port uses that are read from file, Write results to log file, Timeout.</p><p></p><p>//</p><p></p><p></p><p></p><p>import java.net.*;</p><p></p><p>import java.util.Scanner;</p><p></p><p></p><p></p><p>public class Main {</p><p></p><p> public static void main(String[] args) {</p><p></p><p> int startPort = 0;</p><p></p><p> int endPort = 0;</p><p></p><p> String targetIP;</p><p></p><p></p><p></p><p> menu();</p><p></p><p></p><p></p><p> startPort = setStartPort();</p><p></p><p> endPort = setEndPort();</p><p></p><p> targetIP = setTargetIP();</p><p></p><p></p><p></p><p> scanPorts(targetIP, startPort, endPort);</p><p></p><p></p><p></p><p> System.out.println("-----------------------------------------------------");</p><p></p><p> System.out.println("The Port scan is complete.");</p><p></p><p></p><p></p><p> }</p><p></p><p></p><p></p><p> public static void menu() {</p><p></p><p> System.out.println(" Welcome to openScan v1.0.0 ");</p><p></p><p> System.out.println("-----------------------------------------------------");</p><p></p><p> System.out.println("As of now the target must be entered in the form of an");</p><p></p><p> System.out.println("IPv4 address. Attempting to use a domain name or an");</p><p></p><p> System.out.println("IPv6 address will result in an error or the test not");</p><p></p><p> System.out.println("running at all. Example: XXX.XXX.XXX or 127.0.0.1");</p><p></p><p> return;</p><p></p><p> }</p><p></p><p></p><p></p><p> public static boolean isValidIPv4(String hostAddress) {</p><p></p><p> boolean isValid;</p><p></p><p></p><p></p><p> String[] splitIP = hostAddress.split("[.]");</p><p></p><p> int ipPartOne = Integer.parseInt(splitIP[0]);</p><p></p><p> int ipPartTwo = Integer.parseInt(splitIP[1]);</p><p></p><p> int ipPartThree = Integer.parseInt(splitIP[2]);</p><p></p><p> int ipPartFour = Integer.parseInt(splitIP[3]);</p><p></p><p></p><p></p><p> if(! isValidPart(ipPartOne) || ! isValidPart(ipPartTwo) || ! isValidPart(ipPartThree)|| ! isValidPart(ipPartFour)){</p><p></p><p> isValid = false;</p><p></p><p> System.out.println("You have entered an invalid IPv4 address, please try again.");</p><p></p><p> } else if (isReservedIP(splitIP)) {</p><p></p><p> isValid = false;</p><p></p><p> System.out.println("You have entered a reserved IPv4 address, please try again.");</p><p></p><p> } else {</p><p></p><p> isValid = true;</p><p></p><p> System.out.println("Valid IPv4 address!! Attempting to connect now...");</p><p></p><p> }</p><p></p><p></p><p></p><p> return isValid;</p><p></p><p> }</p><p></p><p></p><p></p><p> public static boolean isValidPart(int ipPart) {</p><p></p><p> if (ipPart > 255 || ipPart < 0) {</p><p></p><p> return false;</p><p></p><p> }</p><p></p><p> return true;</p><p></p><p> }</p><p></p><p></p><p></p><p> public static boolean isReservedIP(String[] ipAddress) {</p><p></p><p> if (ipAddress[0].equals("0") && ipAddress[1].equals("0") && ipAddress[2].equals("0") && ipAddress[3].equals("0")) {</p><p></p><p> return true;</p><p></p><p> } else if (ipAddress[0].equals("255") && ipAddress[1].equals("255") && ipAddress[2].equals("255") && ipAddress[3].equals("255")) {</p><p></p><p> return true;</p><p></p><p> } else {</p><p></p><p> return false;</p><p></p><p> }</p><p></p><p> }</p><p></p><p></p><p></p><p> public static boolean isValidPort(int port) {</p><p></p><p> if (port > 65535 || port < 0){</p><p></p><p> return false;</p><p></p><p> }</p><p></p><p> return true;</p><p></p><p> }</p><p></p><p></p><p></p><p> public static int setStartPort() {</p><p></p><p> Scanner keyboard = new Scanner(System.in);</p><p></p><p> boolean isValid;</p><p></p><p> int tempPort = 0;</p><p></p><p></p><p></p><p> do {</p><p></p><p> System.out.println("Enter a starting port.");</p><p></p><p> tempPort = Integer.parseInt(keyboard.nextLine());</p><p></p><p></p><p></p><p> isValid = isValidPort(tempPort);</p><p></p><p></p><p></p><p> } while(isValid == false);</p><p></p><p> keyboard.close();</p><p></p><p> return tempPort;</p><p></p><p> }</p><p></p><p></p><p></p><p> public static int setEndPort() {</p><p></p><p> Scanner keyboard = new Scanner(System.in);</p><p></p><p> boolean isValid;</p><p></p><p> int tempPort = 0;</p><p></p><p></p><p></p><p> do {</p><p></p><p> System.out.println("Enter the ending port.");</p><p></p><p> tempPort = Integer.parseInt(keyboard.nextLine());</p><p></p><p></p><p></p><p> isValid = isValidPort(tempPort);</p><p></p><p></p><p></p><p> } while(isValid == false);</p><p></p><p> keyboard.close();</p><p></p><p> return tempPort;</p><p></p><p> }</p><p></p><p></p><p></p><p> public static String setTargetIP() {</p><p></p><p> Scanner keyboard = new Scanner(System.in);</p><p></p><p> boolean isValid;</p><p></p><p> String tempIP;</p><p></p><p></p><p></p><p> do {</p><p></p><p> System.out.println("Enter the IP of the machine you want to scan.");</p><p></p><p> tempIP = keyboard.nextLine().trim();</p><p></p><p></p><p></p><p> if (! isValidIPv4(tempIP)) {</p><p></p><p> isValid = false;</p><p></p><p> }</p><p></p><p></p><p></p><p> isValid = true;</p><p></p><p></p><p></p><p> } while (isValid == false);</p><p></p><p> keyboard.close();</p><p></p><p> return tempIP;</p><p></p><p> }</p><p></p><p></p><p></p><p> public static void scanPorts(String targetIP, int startPort, int endPort) {</p><p></p><p> for(int i = startPort ;i <= endPort; i++) {</p><p></p><p> try {</p><p></p><p> Socket sock = new Socket(targetIP, i);</p><p></p><p> System.out.println("Port: "+ i + " is open.");</p><p></p><p> sock.close();</p><p></p><p> } catch(Exception e) {</p><p></p><p> // Port closed</p><p></p><p> }</p><p></p><p> }</p><p></p><p> return;</p><p></p><p> }</p><p></p><p></p><p></p><p>}</p><p></p><p>[/CODE]</p><p>[/SPOILER]</p><p>[doublepost=1525398581,1524897502][/doublepost]I re-wrote the application now that I planned most of the main features; all of the basic features from the first design are re-implemented already. </p><p>I'm currently working on writing log files for each scan. I've been working on another project that has a bit more of my attention but I'll continue to work on this in my spare time! After I finish the log files I'll start to work on threading, scan by domain name & IPv6, & scanning intervals of ports rather than just picking a start and end port.</p><p></p><p>Here's a little sample:</p><p>[CODE]import java.util.Scanner;</p><p></p><p>public class ScanSettings {</p><p> private final int startPort;</p><p> private final int endPort;</p><p> private final String targetIP;</p><p></p><p> // Constructors</p><p></p><p> ScanSettings() {</p><p> this.startPort = setStartPort();</p><p> this.endPort = setEndPort();</p><p> this.targetIP = setTargetIP();</p><p> }</p><p></p><p> ScanSettings(int newStartPort, int newEndPort, String newTargetString) {</p><p> this.startPort = newStartPort;</p><p> this.endPort = newEndPort;</p><p> this.targetIP = newTargetString;</p><p> }</p><p></p><p> // Accessor Methods</p><p></p><p> public int getStartPort() {</p><p> return this.startPort;</p><p> }</p><p></p><p> public int getEndPort() {</p><p> return this.endPort;</p><p> }</p><p></p><p> public String getTargetIP() {</p><p> return this.targetIP;</p><p> }</p><p></p><p> // Mutator Methods</p><p></p><p> private static int setStartPort() {</p><p> Scanner keyboard = new Scanner(System.in);</p><p> boolean isValid;</p><p> int tempPort = 0;</p><p></p><p> do {</p><p> System.out.println("Enter a starting port.");</p><p> tempPort = Integer.parseInt(keyboard.nextLine());</p><p></p><p> isValid = PortUtils.isValidPort(tempPort);</p><p></p><p> } while(isValid == false);</p><p> return tempPort;</p><p> }</p><p></p><p> private static int setEndPort() {</p><p> Scanner keyboard = new Scanner(System.in);</p><p> boolean isValid;</p><p> int tempPort = 0;</p><p></p><p> do {</p><p> System.out.println("Enter the ending port.");</p><p> tempPort = Integer.parseInt(keyboard.nextLine());</p><p></p><p> isValid = PortUtils.isValidPort(tempPort);</p><p></p><p> } while(isValid == false);</p><p> return tempPort;</p><p> }</p><p></p><p> private static String setTargetIP() {</p><p> Scanner keyboard = new Scanner(System.in);</p><p> boolean isValid;</p><p> String tempIP;</p><p></p><p> do {</p><p> System.out.println("Enter the IP of the machine you want to scan.");</p><p> tempIP = keyboard.nextLine().trim();</p><p></p><p> if (! IPUtils.isValidIPv4(tempIP)) {</p><p> isValid = false;</p><p> }</p><p></p><p> isValid = true;</p><p></p><p> } while (isValid == false);</p><p> keyboard.close();</p><p> return tempIP;</p><p> }</p><p></p><p></p><p></p><p></p><p></p><p></p><p>}[/CODE]</p><p></p><p></p><p>The Github repo for this project can be found at: <a href="https://github.com/jaytreebeard/openScan" target="_blank">https://github.com/jaytreebeard/openScan</a></p><p>For those of you interested in following the project or contributing/forking it.</p><p></p><p>I wanna thank [USER=66293]@SystemSequence[/USER] for teaching me some new strategies.</p></blockquote><p></p>
[QUOTE="treebeard, post: 433316, member: 79259"] Greetings, openScan is an open source port scanner that I am making in Java, for practice as well as a medium to further my own knowledge. This is a very early release and is only a crude version with minimal features. I'm working through some of the main features and methods in a single class and then I'm going to start from the beginning and structure the project in a more proper OOP style. When I get some more work done I'll post a link to the Github repo in case anyone is interested enough to keep up with it. [URL='https://pastebin.com/CcB98b8D']Link to pastebin[/URL] I hope you enjoy, thanks ^.^ [CENTER]********** openScan is for educational purposes only and I'm in no way responsible for the misuse or misconduct of any individual who chooses to break rules **********[/CENTER] [SPOILER="Original Design of Features"] [CODE=java]// Created by: Justin T // Date: April 28, 2018 // Useful Information: Created using JDK 8 in IntelliJ IDEA. // Purpose: Simple port scanner capable of reading an IPv4 address, starting port, and ending port. // Will print a message if the port is open. // In Progress: Threading, IPv6 support, Search by domain name, Intervals of ports to scan, Designing simple GUI, // Display common port uses that are read from file, Write results to log file, Timeout. // import java.net.*; import java.util.Scanner; public class Main { public static void main(String[] args) { int startPort = 0; int endPort = 0; String targetIP; menu(); startPort = setStartPort(); endPort = setEndPort(); targetIP = setTargetIP(); scanPorts(targetIP, startPort, endPort); System.out.println("-----------------------------------------------------"); System.out.println("The Port scan is complete."); } public static void menu() { System.out.println(" Welcome to openScan v1.0.0 "); System.out.println("-----------------------------------------------------"); System.out.println("As of now the target must be entered in the form of an"); System.out.println("IPv4 address. Attempting to use a domain name or an"); System.out.println("IPv6 address will result in an error or the test not"); System.out.println("running at all. Example: XXX.XXX.XXX or 127.0.0.1"); return; } public static boolean isValidIPv4(String hostAddress) { boolean isValid; String[] splitIP = hostAddress.split("[.]"); int ipPartOne = Integer.parseInt(splitIP[0]); int ipPartTwo = Integer.parseInt(splitIP[1]); int ipPartThree = Integer.parseInt(splitIP[2]); int ipPartFour = Integer.parseInt(splitIP[3]); if(! isValidPart(ipPartOne) || ! isValidPart(ipPartTwo) || ! isValidPart(ipPartThree)|| ! isValidPart(ipPartFour)){ isValid = false; System.out.println("You have entered an invalid IPv4 address, please try again."); } else if (isReservedIP(splitIP)) { isValid = false; System.out.println("You have entered a reserved IPv4 address, please try again."); } else { isValid = true; System.out.println("Valid IPv4 address!! Attempting to connect now..."); } return isValid; } public static boolean isValidPart(int ipPart) { if (ipPart > 255 || ipPart < 0) { return false; } return true; } public static boolean isReservedIP(String[] ipAddress) { if (ipAddress[0].equals("0") && ipAddress[1].equals("0") && ipAddress[2].equals("0") && ipAddress[3].equals("0")) { return true; } else if (ipAddress[0].equals("255") && ipAddress[1].equals("255") && ipAddress[2].equals("255") && ipAddress[3].equals("255")) { return true; } else { return false; } } public static boolean isValidPort(int port) { if (port > 65535 || port < 0){ return false; } return true; } public static int setStartPort() { Scanner keyboard = new Scanner(System.in); boolean isValid; int tempPort = 0; do { System.out.println("Enter a starting port."); tempPort = Integer.parseInt(keyboard.nextLine()); isValid = isValidPort(tempPort); } while(isValid == false); keyboard.close(); return tempPort; } public static int setEndPort() { Scanner keyboard = new Scanner(System.in); boolean isValid; int tempPort = 0; do { System.out.println("Enter the ending port."); tempPort = Integer.parseInt(keyboard.nextLine()); isValid = isValidPort(tempPort); } while(isValid == false); keyboard.close(); return tempPort; } public static String setTargetIP() { Scanner keyboard = new Scanner(System.in); boolean isValid; String tempIP; do { System.out.println("Enter the IP of the machine you want to scan."); tempIP = keyboard.nextLine().trim(); if (! isValidIPv4(tempIP)) { isValid = false; } isValid = true; } while (isValid == false); keyboard.close(); return tempIP; } public static void scanPorts(String targetIP, int startPort, int endPort) { for(int i = startPort ;i <= endPort; i++) { try { Socket sock = new Socket(targetIP, i); System.out.println("Port: "+ i + " is open."); sock.close(); } catch(Exception e) { // Port closed } } return; } } [/CODE] [/SPOILER] [doublepost=1525398581,1524897502][/doublepost]I re-wrote the application now that I planned most of the main features; all of the basic features from the first design are re-implemented already. I'm currently working on writing log files for each scan. I've been working on another project that has a bit more of my attention but I'll continue to work on this in my spare time! After I finish the log files I'll start to work on threading, scan by domain name & IPv6, & scanning intervals of ports rather than just picking a start and end port. Here's a little sample: [CODE]import java.util.Scanner; public class ScanSettings { private final int startPort; private final int endPort; private final String targetIP; // Constructors ScanSettings() { this.startPort = setStartPort(); this.endPort = setEndPort(); this.targetIP = setTargetIP(); } ScanSettings(int newStartPort, int newEndPort, String newTargetString) { this.startPort = newStartPort; this.endPort = newEndPort; this.targetIP = newTargetString; } // Accessor Methods public int getStartPort() { return this.startPort; } public int getEndPort() { return this.endPort; } public String getTargetIP() { return this.targetIP; } // Mutator Methods private static int setStartPort() { Scanner keyboard = new Scanner(System.in); boolean isValid; int tempPort = 0; do { System.out.println("Enter a starting port."); tempPort = Integer.parseInt(keyboard.nextLine()); isValid = PortUtils.isValidPort(tempPort); } while(isValid == false); return tempPort; } private static int setEndPort() { Scanner keyboard = new Scanner(System.in); boolean isValid; int tempPort = 0; do { System.out.println("Enter the ending port."); tempPort = Integer.parseInt(keyboard.nextLine()); isValid = PortUtils.isValidPort(tempPort); } while(isValid == false); return tempPort; } private static String setTargetIP() { Scanner keyboard = new Scanner(System.in); boolean isValid; String tempIP; do { System.out.println("Enter the IP of the machine you want to scan."); tempIP = keyboard.nextLine().trim(); if (! IPUtils.isValidIPv4(tempIP)) { isValid = false; } isValid = true; } while (isValid == false); keyboard.close(); return tempIP; } }[/CODE] The Github repo for this project can be found at: [URL]https://github.com/jaytreebeard/openScan[/URL] For those of you interested in following the project or contributing/forking it. I wanna thank [USER=66293]@SystemSequence[/USER] for teaching me some new strategies. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Development
openScan [Java]
Top