https://github.com/mattwright324/jports
Flexible, fast, multithreaded address and port scanning library for Java.
https://github.com/mattwright324/jports
java-library multithreading-library network-scanning port-scanner
Last synced: 25 days ago
JSON representation
Flexible, fast, multithreaded address and port scanning library for Java.
- Host: GitHub
- URL: https://github.com/mattwright324/jports
- Owner: mattwright324
- License: mit
- Created: 2019-08-03T00:08:33.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2024-09-13T11:29:37.000Z (almost 2 years ago)
- Last Synced: 2025-10-28T20:41:46.447Z (9 months ago)
- Topics: java-library, multithreading-library, network-scanning, port-scanner
- Language: Java
- Homepage:
- Size: 21.5 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jports
Flexible, fast, multithreaded address and port scanning library for Java.
## Features
- Java 8
- Flexible inputs to accept a variety of formats
- Single address
- Multiple addresses
- Address range with start and end
- Address range with CIDR notation
- Endless scanning
- With a given address, continuously increase or decrease, stopping when you want it to.
- Check for open port(s)
- Multithreaded, specify thread count
## Sample(s)
#### Constructors
Examples of creating addresses and address blocks
```java
new IPv4Address(3232235521L); // 192.168.0.1
new IPv4Address("192.168.0.1");
new IPv4Address("192.168.0.260"); // 192.168.1.4
new IPv4Address("999.999.999.999"); // 234.234.234.231
new IPv4AddressBlock("192.168.0.0", "192.168.1.255");
new IPv4AddressBlock(new IPv4Address("192.168.0.0"), new IPv4Address("192.168.1.255"));
new IPv4AddressBlock("192.168.0.0/24");
new IPv4AddressBlock("192.168.0.0", 24);
new IPv4AddressBlock(new IPv4Address("192.168.0.0"), 24);
// Scan through just IP addresses
new IPv4BlockScan(new IPv4AddressBlock("192.168.0.0/24"));
new IPv4BlockScan(new IPv4Address("192.168.0.0"), ScanMethod.SINGLE_ADDRESS);
new IPv4BlockScan(new IPv4Address("192.168.0.0"), ScanMethod.ENDLESS_INCREASE);
new IPv4BlockScan(new IPv4Address("192.168.0.0"), ScanMethod.ENDLESS_DECREASE);
new IPv4BlockScan(Arrays.asList(new IPv4Address("192.168.1.1"), new IPv4Address("192.168.1.145"))));
// Scan through IP addresses and ports
new IPv4BlockPortScan(new IPv4AddressBlock("192.168.0.0/24"));
new IPv4BlockPortScan(new IPv4Address("192.168.0.0"), ScanMethod.SINGLE_ADDRESS);
new IPv4BlockPortScan(new IPv4Address("192.168.0.0"), ScanMethod.ENDLESS_INCREASE);
new IPv4BlockPortScan(new IPv4Address("192.168.0.0"), ScanMethod.ENDLESS_DECREASE);
new IPv4BlockPortScan(Arrays.asList(new IPv4Address("192.168.1.1"), new IPv4Address("192.168.1.145"))));
```
#### Traversing IP blocks
Can manually cycle through a block of addresses.
```java
IPv4AddressBlock block = new IPv4AddressBlock("192.168.0.0", "192.168.1.255");
IPv4Address address = block.getFirstAddress();
do {
System.out.println(address.getAddress());
address = address.nextAddress();
} while (address.getDecimal() < block.getLastAddress().getDecimal());
```
Or use the address scanner to do so in a faster, multithreaded context.
```java
IPv4AddressBlock addressBlock = new IPv4AddressBlock("192.168.0.0", "192.168.1.255");
IPv4BlockScan blockScan = new IPv4BlockScan(addressBlock)
.setThreadCount(64)
.setConsumingMethod(YourApplication::consumingMethod)
.executeAndAwait();
```
#### Port scanner example
In this example, we are creating a range of the most commonly expected local address range
and have a list of the most common ports used for web pages.
We initiate the scan and consume the found results, expecting these to be web pages.
Using the Jsoup library, we attempt to grab the page and print out the URL and page title.
```java
public class LocalScanner {
private IPv4AddressBlock localBlock = new IPv4AddressBlock("192.168.0.0", "192.168.1.255");
private List ports = Arrays.asList(80, 81, 443, 8080, 8000);
public static void main(String[] args) {
LocalScanner scanner = new LocalScanner();
scanner.startScan();
}
public void startScan() {
IPv4BlockPortScan portScan = new IPv4BlockPortScan(localBlock)
.setPorts(ports)
.setThreadCount(64)
.setCheckPorts(true) // default true, false to consume all address:port combinations
.setCheckTimeout(150)
.setConsumingMethod(this::consumingMethod)
.executeAndAwait();
}
public void consumingMethod(IPv4AddressPort addressPort) {
// further process, store in database, display on screen, etc.
String expectedWebpage;
if(addressPort.getPort() == 80) {
expectedWebpage = "http://" + addressPort.getAddress().getAddress();
} else if(addressPort.getPort() == 443) {
expectedWebpage = "https://" + addressPort.getAddress().getAddress();
} else {
expectedWebpage = "http://" + addressPort.getFullAddress();
}
try {
Document document = Jsoup.connect(expectedWebpage).get();
System.out.printf("%s size=%s title=%s\n", expectedWebpage, document.html().length(), document.title());
} catch (IOException e) {
System.err.printf("%s %s\n", expectedWebpage, e.getClass().getSimpleName()+": "+e.getLocalizedMessage());
}
}
}
```