Scan subnets in parallel, update readme, update gitignore
This commit is contained in:
parent
6642554473
commit
2caf97d535
3 changed files with 80 additions and 62 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,5 +2,6 @@
|
|||
!.gitignore
|
||||
!.screenshot.png
|
||||
minipam
|
||||
MinIPAM
|
||||
*.yaml
|
||||
*.json
|
|
@ -11,6 +11,9 @@ there is no authorization mechanism built in.
|
|||
Scanning is kind of slow, but I prefer to keep it that way, since I don't need it to be fast, and I don't want to waste
|
||||
my compute resources. It doesn't matter for me if my scan completes within 1 minute or within 30 minutes.
|
||||
|
||||
Subnets are scanned in parallel, but addresses in each subnet are still scanned sequentially. So complete scan takes as
|
||||
much time, as scanning of biggest subnet that you have.
|
||||
|
||||
![Screenshot](.screenshot.png)
|
||||
|
||||
# Compilation
|
||||
|
@ -33,9 +36,13 @@ scan_subnets:
|
|||
- 192.168.145.0/24
|
||||
- 10.250.100.64.0/27
|
||||
delay_between_scans: 15m
|
||||
#Setting this to absolute path seems like a good idea :)
|
||||
persistence_location: "data.json"
|
||||
#Don't scan network and broadcast address, usually you want to leave this set to true
|
||||
exclude_special_addresses: true
|
||||
use_tls: false
|
||||
#IF use_tls is set to false, following two options are ignored.
|
||||
#key and cert and fullchain can be in one file. In this case, specify the same file in both fields
|
||||
tls_key_file: "key.pem"
|
||||
tls_cert_file: "fullchain.pem"
|
||||
```
|
||||
|
|
18
minipam.go
18
minipam.go
|
@ -12,6 +12,7 @@ import (
|
|||
"net/netip"
|
||||
"os"
|
||||
"os/exec"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -120,9 +121,13 @@ func ping(addr string) bool {
|
|||
|
||||
func scanner() {
|
||||
for {
|
||||
var wg sync.WaitGroup
|
||||
var mutex sync.Mutex
|
||||
for _, subnet := range conf.ScanSubnets {
|
||||
|
||||
for _, v := range conf.ScanSubnets {
|
||||
|
||||
go func(v string) {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
persistenceSubnet, ok := p.Subnets[v]
|
||||
if !ok {
|
||||
persistenceSubnet = SubnetT{}
|
||||
|
@ -132,7 +137,7 @@ func scanner() {
|
|||
prefix, err := netip.ParsePrefix(v)
|
||||
if err != nil {
|
||||
log.Printf("Error: %s", err)
|
||||
continue
|
||||
return
|
||||
}
|
||||
prefix = prefix.Masked()
|
||||
addr := prefix.Addr()
|
||||
|
@ -188,9 +193,14 @@ func scanner() {
|
|||
|
||||
addr = addr.Next()
|
||||
}
|
||||
mutex.Lock()
|
||||
p.Subnets[v] = persistenceSubnet
|
||||
mutex.Unlock()
|
||||
log.Printf("Scan of %s finished", v)
|
||||
}(subnet)
|
||||
}
|
||||
log.Printf("Scan finished")
|
||||
wg.Wait()
|
||||
log.Printf("All scans finished")
|
||||
f, err := os.Create(conf.PersistenceLocation)
|
||||
if err != nil {
|
||||
log.Printf("Failed to save persistence: %s", err)
|
||||
|
|
Loading…
Reference in a new issue