This commit is contained in:
juzeon
2024-02-12 10:13:18 -05:00
committed by yuhan6665
parent fa310c5c0f
commit 8e0e975703
3 changed files with 23 additions and 85 deletions
+13 -17
View File
@@ -21,13 +21,12 @@ const (
type HostType int
type Host struct {
IP net.IP
Origin string
Type HostType
Infinity bool
IP net.IP
Origin string
Type HostType
}
func Iterate(reader io.Reader, infinity bool) <-chan Host {
func Iterate(reader io.Reader) <-chan Host {
scanner := bufio.NewScanner(reader)
hostChan := make(chan Host)
go func() {
@@ -41,10 +40,9 @@ func Iterate(reader io.Reader, infinity bool) <-chan Host {
if ip != nil && (ip.To4() != nil || enableIPv6) {
// ip address
hostChan <- Host{
IP: ip,
Origin: line,
Type: HostTypeIP,
Infinity: infinity,
IP: ip,
Origin: line,
Type: HostTypeIP,
}
continue
}
@@ -67,10 +65,9 @@ func Iterate(reader io.Reader, infinity bool) <-chan Host {
ip = net.ParseIP(addr.String())
if ip != nil {
hostChan <- Host{
IP: ip,
Origin: line,
Type: HostTypeCIDR,
Infinity: false,
IP: ip,
Origin: line,
Type: HostTypeCIDR,
}
}
addr = addr.Next()
@@ -80,10 +77,9 @@ func Iterate(reader io.Reader, infinity bool) <-chan Host {
if ValidateDomainName(line) {
// domain
hostChan <- Host{
IP: nil,
Origin: line,
Type: HostTypeDomain,
Infinity: infinity,
IP: nil,
Origin: line,
Type: HostTypeDomain,
}
continue
}