| 112 | return exist |
| 113 | } |
| 114 | func IterateAddr(addr string) <-chan Host { |
| 115 | hostChan := make(chan Host) |
| 116 | _, _, err := net.ParseCIDR(addr) |
| 117 | if err == nil { |
| 118 | // is CIDR |
| 119 | return Iterate(strings.NewReader(addr)) |
| 120 | } |
| 121 | ip := net.ParseIP(addr) |
| 122 | if ip == nil { |
| 123 | ip, err = LookupIP(addr) |
| 124 | if err != nil { |
| 125 | close(hostChan) |
| 126 | slog.Error("Not a valid IP, IP CIDR or domain", "addr", addr) |
| 127 | return hostChan |
| 128 | } |
| 129 | } |
| 130 | go func() { |
| 131 | slog.Info("Enable infinite mode", "init", ip.String()) |
| 132 | lowIP := ip |
| 133 | highIP := ip |
| 134 | hostChan <- Host{ |
| 135 | IP: ip, |
| 136 | Origin: addr, |
| 137 | Type: HostTypeIP, |
| 138 | } |
| 139 | for i := 0; i < math.MaxInt; i++ { |
| 140 | if i%2 == 0 { |
| 141 | lowIP = NextIP(lowIP, false) |
| 142 | hostChan <- Host{ |
| 143 | IP: lowIP, |
| 144 | Origin: lowIP.String(), |
| 145 | Type: HostTypeIP, |
| 146 | } |
| 147 | } else { |
| 148 | highIP = NextIP(highIP, true) |
| 149 | hostChan <- Host{ |
| 150 | IP: highIP, |
| 151 | Origin: highIP.String(), |
| 152 | Type: HostTypeIP, |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | }() |
| 157 | return hostChan |
| 158 | } |
| 159 | func LookupIP(addr string) (net.IP, error) { |
| 160 | ips, err := net.LookupIP(addr) |
| 161 | if err != nil { |