-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (65 loc) · 2.1 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"bufio"
"fmt"
"github.com/cheggaaa/pb/v3"
"log"
"net"
"os"
)
var banner = `
▄████ ▒█████ ██▀███ ▄▄▄ ███▄ █ ▄████
██▒ ▀█▒▒██▒ ██▒▓██ ▒ ██▒▒████▄ ██ ▀█ █ ██▒ ▀█▒
▒██░▄▄▄░▒██░ ██▒▓██ ░▄█ ▒▒██ ▀█▄ ▓██ ▀█ ██▒▒██░▄▄▄░
░▓█ ██▓▒██ ██░▒██▀▀█▄ ░██▄▄▄▄██ ▓██▒ ▐▌██▒░▓█ ██▓
░▒▓███▀▒░ ████▓▒░░██▓ ▒██▒ ▓█ ▓██▒▒██░ ▓██░░▒▓███▀▒
░▒ ▒ ░ ▒░▒░▒░ ░ ▒▓ ░▒▓░ ▒▒ ▓▒█░░ ▒░ ▒ ▒ ░▒ ▒
░ ░ ░ ▒ ▒░ ░▒ ░ ▒░ ▒ ▒▒ ░░ ░░ ░ ▒░ ░ ░
░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░ ▒ ░ ░ ░ ░ ░ ░
░ ░ ░ ░ ░ ░ ░ ░
`
func inc(ip net.IP) {
for j := len(ip) - 1; j >= 0; j-- {
ip[j]++
if ip[j] > 0 {
break
}
}
}
func expandCidr(cidr string, result chan []string) {
ip, ipnet, _ := net.ParseCIDR(cidr)
var ipList []string
for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) {
ipList = append(ipList, ip.String())
}
result <- ipList
}
func CidrIp(files string) {
result := make(chan []string)
file, err := os.Open(files)
if err != nil {
log.Fatal(err)
}
scanner := bufio.NewScanner(file)
bar := pb.StartNew(len(result))
for scanner.Scan() {
go expandCidr(scanner.Text(), result)
for _, ip := range <-result {
w, _ := os.OpenFile("result.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
_, _ = w.WriteString(ip + "\n")
bar.Increment()
}
}
bar.Finish()
defer func(file *os.File) {
_ = file.Close()
}(file)
close(result)
}
func main() {
var list string
fmt.Print(banner)
fmt.Print("Enter Ur List : ")
_, _ = fmt.Scan(&list)
CidrIp(list)
}