Add back infinity mode (default for single address)

This commit is contained in:
yuhan6665
2024-02-11 19:38:34 -05:00
parent 7a987c9459
commit d2842f1ad7
3 changed files with 79 additions and 19 deletions
+47 -1
View File
@@ -3,13 +3,44 @@ package main
import (
"crypto/tls"
"log/slog"
"math/big"
"net"
"strconv"
"strings"
"sync"
"time"
)
func ScanTLS(host Host, out chan<- string) {
type Scanner struct {
mu *sync.Mutex
high net.IP
low net.IP
}
func (s *Scanner) Scan(host Host, out chan<- string, increment bool) {
if host.Infinity && host.IP != nil {
s.mu.Lock()
if s.high == nil {
s.high = host.IP
s.low = host.IP
host.Origin = ""
host.Type = HostTypeIP
} else if increment {
s.high = nextIP(s.high, increment)
host.IP = s.high
} else {
s.low = nextIP(s.low, increment)
host.IP = s.low
}
s.mu.Unlock()
}
ScanTLS(host, out, increment)
if host.Infinity && host.IP != nil {
go s.Scan(host, out, increment)
}
}
func ScanTLS(host Host, out chan<- string, increment bool) {
if host.IP == nil {
ips, err := net.LookupIP(host.Origin)
if err != nil {
@@ -71,3 +102,18 @@ func ScanTLS(host Host, out chan<- string) {
"origin", host.Origin,
"tls", tls.VersionName(state.Version), "alpn", alpn, "cert-domain", domain, "cert-issuer", issuers)
}
func nextIP(ip net.IP, increment bool) net.IP {
// Convert to big.Int and increment
ipb := big.NewInt(0).SetBytes([]byte(ip))
if increment {
ipb.Add(ipb, big.NewInt(1))
} else {
ipb.Sub(ipb, big.NewInt(1))
}
// Add leading zeros
b := ipb.Bytes()
b = append(make([]byte, len(ip)-len(b)), b...)
return net.IP(b)
}