-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
48 lines (43 loc) · 793 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"os"
"strings"
"net"
"github.com/korylprince/ipnetgen"
)
func displayIps(cidrInput string){
cidrInput = strings.TrimSpace(cidrInput)
if(strings.Contains(cidrInput,"/")){
gen, err := ipnetgen.New(cidrInput)
if err != nil {
//do something with err
}
for ip := gen.Next(); ip != nil; ip = gen.Next() {
fmt.Println(ip)
}
}else{
ip := net.ParseIP(cidrInput)
if ip != nil {
fmt.Println(cidrInput)
}
}
}
func main() {
var cidrInput string
var input string
//Check here if one or more, and convert to strings
if len(os.Args) > 1 {
cidrInput = os.Args[1]
displayIps(cidrInput)
}else{
for {
_, err := fmt.Scanln(&input)
if err != nil {
break
}else{
displayIps(input)
}
}
}
}