🤬
  • ■ ■ ■ ■ ■ ■
    Projects/Simple_port_scanner/.gitignore
     1 +/target/
     2 +!.mvn/wrapper/maven-wrapper.jar
     3 + 
     4 +### STS ###
     5 +.apt_generated
     6 +.classpath
     7 +.factorypath
     8 +.project
     9 +.settings
     10 +.springBeans
     11 +.sts4-cache
     12 + 
     13 +### IntelliJ IDEA ###
     14 +.idea
     15 +*.iws
     16 +*.iml
     17 +*.ipr
     18 + 
     19 +### NetBeans ###
     20 +/nbproject/private/
     21 +/build/
     22 +/nbbuild/
     23 +/dist/
     24 +/nbdist/
     25 +/.nb-gradle/
     26 + 
     27 +*.xml.versionsBackup
  • ■ ■ ■ ■ ■ ■
    Projects/Simple_port_scanner/README.md
     1 +# Simple Port Scanner
     2 + 
     3 +![image](https://user-images.githubusercontent.com/32443720/133543195-d2d82cc6-0f8b-40bc-81d5-74de6ff130e2.png)
     4 + 
     5 +## :information_source: technologies used
     6 + 
     7 +* Java
     8 + 
     9 +## :information_source: How use?
     10 +```bash
     11 +# Clone the repository
     12 +$ git clone https://github.com/kurogai/100-redteam-projects
     13 + 
     14 +# Enter the repository
     15 +$ cd 100-redteam-projects/Projects/Simple_port_scanner
     16 + 
     17 +# Open a terminal and run
     18 +$ java -jar Simple_port_scanner.jar targetIP
     19 + 
     20 +# example Usage
     21 +$ java -jar Simple_port_scanner.jar 127.0.0.1
     22 + 
     23 +```
     24 + 
     25 +## :books: References
     26 + https://www.theswdeveloper.com/post/create-a-port-scanner-with-java
     27 +
     28 + https://stackoverflow.com/questions/26004337/java-multithreaded-port-scanner
     29 +
     30 + https://www.youtube.com/watch?v=WbLpkL03dRI
     31 + 
  • Projects/Simple_port_scanner/Simple_port_scanner.jar
    Binary file.
  • ■ ■ ■ ■ ■ ■
    Projects/Simple_port_scanner/pom.xml
     1 +<?xml version="1.0" encoding="UTF-8"?>
     2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
     3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     5 + <modelVersion>4.0.0</modelVersion>
     6 + 
     7 + <groupId>org.scanner</groupId>
     8 + <artifactId>Simple_port_scanner</artifactId>
     9 + <version>1.0-SNAPSHOT</version>
     10 + 
     11 + <properties>
     12 + <maven.compiler.source>11</maven.compiler.source>
     13 + <maven.compiler.target>11</maven.compiler.target>
     14 + </properties>
     15 + 
     16 +</project>
  • ■ ■ ■ ■ ■ ■
    Projects/Simple_port_scanner/src/main/java/META-INF/MANIFEST.MF
     1 +Manifest-Version: 1.0
     2 +Main-Class: com.scanner.SimpleScanner
     3 +
     4 + 
  • ■ ■ ■ ■ ■ ■
    Projects/Simple_port_scanner/src/main/java/com/scanner/SimpleScanner.java
     1 +package com.scanner;
     2 + 
     3 +import java.io.IOException;
     4 +import java.net.InetSocketAddress;
     5 +import java.net.Socket;
     6 +import java.util.ArrayList;
     7 +import java.util.List;
     8 +import java.util.concurrent.ConcurrentLinkedQueue;
     9 +import java.util.concurrent.ExecutorService;
     10 +import java.util.concurrent.Executors;
     11 +import java.util.concurrent.TimeUnit;
     12 +import java.util.concurrent.atomic.AtomicInteger;
     13 + 
     14 +public class SimpleScanner {
     15 + 
     16 + 
     17 + public static void main(String[] args) {
     18 + // verification if has ip target
     19 + if(args.length == 1){
     20 + String ipTarget = args[0];
     21 + List openPorts = portScan(ipTarget);
     22 + openPorts.forEach(port -> System.out.println(ipTarget + ", port open: " + port));
     23 + }
     24 + else {
     25 + System.out.println("Correct usage: script, IP address target");
     26 + System.exit(0);
     27 + }
     28 + }
     29 + 
     30 + public static List portScan(String ip) {
     31 + ConcurrentLinkedQueue openPorts = new ConcurrentLinkedQueue<>();
     32 + ExecutorService executorService = Executors.newFixedThreadPool(50);
     33 + AtomicInteger port = new AtomicInteger(0);
     34 + while (port.get() < 65535) {
     35 + final int currentPort = port.getAndIncrement();
     36 + executorService.submit(() -> {
     37 + try {
     38 + Socket socket = new Socket();
     39 + // try connection
     40 + socket.connect(new InetSocketAddress(ip, currentPort), 200);
     41 + socket.close();
     42 + // if Connection established add to ConcurrentLinkedQueue
     43 + openPorts.add(currentPort);
     44 + }
     45 + catch (IOException e) {
     46 + }
     47 + 
     48 + });
     49 + }
     50 + executorService.shutdown();
     51 + try {
     52 + executorService.awaitTermination(10, TimeUnit.MINUTES);
     53 + }
     54 + catch (InterruptedException e) {
     55 + e.printStackTrace();
     56 + }
     57 + 
     58 + List openPortList = new ArrayList<>();
     59 + System.out.println("open Ports Queue: " + openPorts.size());
     60 + while (!openPorts.isEmpty()) {
     61 + // after verify turns ConcurrentLinkedQueue into List
     62 + openPortList.add(openPorts.poll());
     63 + }
     64 + return openPortList;
     65 + }
     66 +}
     67 + 
Please wait...
Page is in error, reload to recover