@@ -39,7 +39,7 @@ func IPListWriteFrom(
3939 }
4040
4141 if isPiped || isTyping || stat .Size () > 0 {
42- IPListWriteFromStdin ()
42+ IPListWriteFromStdin (ip , iprange , cidr )
4343 }
4444 }
4545
@@ -63,11 +63,10 @@ func IPListWriteFrom(
6363 }
6464
6565 if file && FileExists (input ) {
66- if err := IPListWriteFromFile (input ); err == nil {
66+ if err := IPListWriteFromFile (input , ip , iprange , cidr ); err == nil {
6767 continue
6868 }
6969 }
70-
7170 return ErrInvalidInput
7271 }
7372
@@ -80,8 +79,8 @@ func IPListWriteFromAllSrcs(inputs []string) error {
8079 return IPListWriteFrom (inputs , true , true , true , true , true )
8180}
8281
83- // IPListFromCIDRWrite is the same as IPListFromCIDR with O(1) memory by discarding
84- // IPs after printing.
82+ // IPListFromCIDRWrite is the same as IPListFromCIDR with O(1) memory
83+ // by discarding IPs after printing.
8584func IPListWriteFromCIDR (cidrStr string ) error {
8685 _ , ipnet , err := net .ParseCIDR (cidrStr )
8786 if err != nil {
@@ -161,25 +160,37 @@ func IPListWriteFromIPRangeStr(rStr string) error {
161160
162161// IPListWriteFromReader returns a list of IPs after reading from a reader; the
163162// reader should have IPs per-line.
164- func IPListWriteFromReader (r io.Reader ) {
163+ func IPListWriteAllFromReader (r io.Reader ) {
164+ IPListWriteFromReader (r , true , true , true )
165+ }
166+
167+ // IPListWriteFromReader returns a list of IPs after reading from a reader
168+ // from selected sources; the reader should have IPs per-line.
169+ func IPListWriteFromReader (
170+ r io.Reader ,
171+ ip bool ,
172+ iprange bool ,
173+ cidr bool ) {
165174 scanner := bufio .NewScanner (r )
166175 for scanner .Scan () {
167- ipStr := strings .TrimSpace (scanner .Text ())
168- if ipStr == "" {
176+ input := strings .TrimSpace (scanner .Text ())
177+ if input == "" {
169178 break
170179 }
171180
172- if err := IPListWriteFromIPRangeStr (ipStr ); err == nil {
173- continue
181+ if iprange {
182+ if err := IPListWriteFromIPRangeStr (input ); err == nil {
183+ continue
184+ }
174185 }
175186
176- if StrIsIPStr (ipStr ) {
177- fmt .Println (ipStr )
187+ if ip && StrIsIPStr (input ) {
188+ fmt .Println (input )
178189 continue
179190 }
180191
181- if StrIsCIDRStr (ipStr ) {
182- if err := IPListWriteFromCIDR (ipStr ); err == nil {
192+ if cidr && StrIsCIDRStr (input ) {
193+ if err := IPListWriteFromCIDR (input ); err == nil {
183194 continue
184195 }
185196 }
@@ -190,25 +201,56 @@ func IPListWriteFromReader(r io.Reader) {
190201
191202// IPListWriteFromStdin returns a list of IPs from a stdin; the IPs should be 1
192203// per line.
193- func IPListWriteFromStdin () {
194- IPListWriteFromReader (os .Stdin )
204+ func IPListWriteAllFromStdin () {
205+ IPListWriteAllFromReader (os .Stdin )
206+ }
207+
208+ // IPListWriteFromStdin returns a list of IPs from a stdin from selected
209+ // sources; the IPs should be 1 per line.
210+ func IPListWriteFromStdin (
211+ ip bool ,
212+ iprange bool ,
213+ cidr bool ) {
214+ IPListWriteFromReader (os .Stdin , ip , iprange , cidr )
195215}
196216
197217// IPListWriteFromFile returns a list of IPs found in a file.
198- func IPListWriteFromFile (pathToFile string ) error {
218+ func IPListWriteAllFromFile (pathToFile string ) error {
219+ return IPListWriteFromFile (pathToFile , true , true , true )
220+ }
221+
222+ // IPListWriteFromSrcFile returns a list of IPs from selected sources found
223+ // in a file.
224+ func IPListWriteFromFile (
225+ pathToFile string ,
226+ ip bool ,
227+ iprange bool ,
228+ cidr bool ,
229+ ) error {
199230 f , err := os .Open (pathToFile )
200231 if err != nil {
201232 return err
202233 }
203-
204- IPListWriteFromReader (f )
234+ IPListWriteFromReader (f , ip , iprange , cidr )
205235 return nil
206236}
207237
208- // IPListWriteFromFiles returns a list of IPs found in a list of files.
209- func IPListWriteFromFiles (paths []string ) error {
238+ // IPListWriteFromFiles returns a list of IPs found in a list of files from
239+ // all sources.
240+ func IPListWriteAllFromFiles (paths []string ) error {
241+ return IPListWriteFromFiles (paths , true , true , true )
242+ }
243+
244+ // IPListWriteFromFiles returns a list of IPs found in a list of files from
245+ // select sources.
246+ func IPListWriteFromFiles (
247+ paths []string ,
248+ ip bool ,
249+ iprange bool ,
250+ cidr bool ,
251+ ) error {
210252 for _ , p := range paths {
211- if err := IPListWriteFromFile (p ); err != nil {
253+ if err := IPListWriteFromFile (p , ip , iprange , cidr ); err != nil {
212254 return err
213255 }
214256 }
0 commit comments