forked from lilendian0x00/xray-knife
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfscanner.go
53 lines (44 loc) · 1.29 KB
/
cfscanner.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
package scan
import (
"github.com/reenigneserever/xray-knife/utils"
"github.com/reenigneserever/xray-knife/utils/customlog"
"os"
"strings"
"github.com/spf13/cobra"
)
var (
subnets string
threadCount uint16
shuffleIPs bool
)
// CFscannerCmd represents the cfscanner command
var CFscannerCmd = &cobra.Command{
Use: "cfscanner",
Short: "Cloudflare's edge IP scanner (delay, downlink, uplink)",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
var cidrs []string
var totalIPs []string
if _, err := os.Stat(subnets); err == nil {
cidrs = utils.ParseFileByNewline(subnets)
} else {
cidrs = strings.Split(subnets, ",")
}
for _, cidr := range cidrs {
listIP, err := utils.CIDRtoListIP(cidr)
if err != nil {
customlog.Printf(customlog.Failure, "Error when parsing a CIDR: %v\n", err)
continue
}
totalIPs = append(totalIPs, listIP...)
}
if len(totalIPs) <= 0 {
customlog.Printf(customlog.Failure, "Scanner failed! => No IP detected\n")
}
},
}
func init() {
ScanCmd.PersistentFlags().StringVarP(&subnets, "subnets", "s", "", "File or subnets: X.X.X.X/Y OR subnets.txt ")
ScanCmd.PersistentFlags().Uint16VarP(&threadCount, "threads", "t", 10, "Count of threads")
ScanCmd.Flags().BoolVarP(&shuffleIPs, "shuffle", "e", true, "Shuffle list of IPs")
}