From 4333a433a08652a71c52cd4b268c75995c75fc59 Mon Sep 17 00:00:00 2001 From: sandeep <8293321+ehsandeep@users.noreply.github.com> Date: Tue, 13 Sep 2022 04:33:21 +0530 Subject: [PATCH 1/5] version update --- cmd/mapcidr/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/mapcidr/main.go b/cmd/mapcidr/main.go index 5a3de16b..4d987566 100644 --- a/cmd/mapcidr/main.go +++ b/cmd/mapcidr/main.go @@ -54,12 +54,12 @@ const banner = ` ____________ ___ __ _ ___ ____ / ___/ _/ _ \/ _ \ / ' \/ _ '/ _ \/ /___/ // // / , _/ -/_/_/_/\_,_/ .__/\___/___/____/_/|_| v1.0.1 +/_/_/_/\_,_/ .__/\___/___/____/_/|_| v1.0.3-dev /_/ ` // Version is the current version of mapcidr -const Version = `v1.0.1` +const Version = `v1.0.3-dev` // showBanner is used to show the banner to the user func showBanner() { From 4bb3bd9fa138f17df93d2684a1c8d997ba5f5ed9 Mon Sep 17 00:00:00 2001 From: Shubham Rasal Date: Wed, 14 Sep 2022 16:16:28 +0530 Subject: [PATCH 2/5] Solve issue with sort / reverse sort option #103 (#104) * Add IP range input support (ipv4, ipv6) #98 - Update main.go to accept IP range from stdin and print the possible CIDRs * Add test cases to validate RangeTOCIDR function - Add test case for singleCIDR, multipleCIDRs and ip6 range. - Convert the []net.IPNet to []string before comparing the expected. * Add check to validate the IP range and Update README - Accept the list of IP ranges - Fatal() if the first IP is greater than last IP - Fatal() if IP range contains more than 2 values. - Update README.md to add the ip range input documentation. * Update IP range functionality to accept only single range - Remove the unnecessary for loop. - Update the READ.md to remove the IP range list block * Remove the IP comparing logic to a function - Add new function `GetCIDRFromIPRange` which validate the input If input is wrong send the error otherwise returns the sorted list of CIDR ranges. - Update the test case to test `GetCIDRFromIPRange` function. - Add the wrong input IP range test case. - Remove the IP comparing and sorting logic from main.go * Remove the typo * Update code to handle the IP range expansion - Update the `main.go` to handle the case to IP range expansion - rename the `CIDRFromIPRange` to `IPRangeInput` - Add the if block which handles the case when Input is IP range. * Remove old cidrs before appending new cidrs in allCidrs * Move logic to common function to avoid repetition. Do not overwrite allCidrs list instead use a separate net.IP list. * Add tests for process function, * Break wg.Add(2) into two wg.Add(1) * Make wg.Done as defer * Handle case of multiple IP range, combination of CIDR and IP range - Input may contain the multiple CIDRs and multiple IP ranges eg. `166.8.0.0/16,166.11.0.0/16,166.9.0.0-166.10.255.255` - Handle the above input for arggregation, count, etc - Move the string split logic from `main()` to `process()` function - Add the new variable IPRangeMap which stores multiple IP range * Add the comment for ipRange block * Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. * Resolve the requested changes - Remove the IPRangeInput variable - Simplify checking len of IPRange Input - Use require package for checking expected and got in test cases * Replace string.Equal to require package for testing * Update goflags version - mapcidr and goflag had conflicting version to solve that update the goflags version * Update sorting behaviour - Expand the CIDR then sort - Before it was converting IPs to CIDR then sort. - Add `getIPList()` which expands the CIDRs to IP for sorting * Remove the unnecessary err block Co-authored-by: Sandeep Singh Co-authored-by: Jaideep Khandelwal Co-authored-by: Siddharth Shashikar <60960197+shashikarsiddharth@users.noreply.github.com> --- cmd/mapcidr/main.go | 36 +++++++++++++++++++++------ cmd/mapcidr/main_test.go | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/cmd/mapcidr/main.go b/cmd/mapcidr/main.go index 4d987566..b4502624 100644 --- a/cmd/mapcidr/main.go +++ b/cmd/mapcidr/main.go @@ -107,8 +107,8 @@ func ParseOptions() *Options { // Miscellaneous flagSet.CreateGroup("miscellaneous", "Miscellaneous", - flagSet.BoolVarP(&options.SortAscending, "sort", "s", false, "Sort input IPs/CIDRs in ascending order"), - flagSet.BoolVarP(&options.SortDescending, "sort-reverse", "sr", false, "Sort input IPs/CIDRs in descending order"), + flagSet.BoolVarP(&options.SortAscending, "sort", "s", false, "Sort input IPs in ascending order"), + flagSet.BoolVarP(&options.SortDescending, "sort-reverse", "sr", false, "Sort input IPs in descending order"), flagSet.BoolVarP(&options.Shuffle, "shuffle-ip", "si", false, "Shuffle Input IPs in random order"), flagSet.StringVarP(&options.ShufflePorts, "shuffle-port", "sp", "", "Shuffle Input IP:Port in random order"), ) @@ -175,6 +175,10 @@ func (options *Options) validateOptions() error { if options.FilterIP != nil && options.MatchIP != nil { return errors.New("both match and filter mode specified") } + + if (options.SortAscending || options.SortDescending) && options.Aggregate { + return errors.New("can sort only IPs. sorting can't be used with aggregate") + } return nil } @@ -390,17 +394,18 @@ func process(wg *sync.WaitGroup, chancidr, outputchan chan string) { } if hasSort { + ips := getIPList(allCidrs) if options.SortDescending { - sort.Slice(allCidrs, func(i, j int) bool { - return bytes.Compare(allCidrs[j].IP, allCidrs[i].IP) < 0 + sort.Slice(ips, func(i, j int) bool { + return bytes.Compare(ips[j], ips[i]) < 0 }) } else { - sort.Slice(allCidrs, func(i, j int) bool { - return bytes.Compare(allCidrs[i].IP, allCidrs[j].IP) < 0 + sort.Slice(ips, func(i, j int) bool { + return bytes.Compare(ips[i], ips[j]) < 0 }) } - for _, cidr := range allCidrs { - outputchan <- cidr.String() + for _, ip := range ips { + outputchan <- ip.String() } } @@ -494,3 +499,18 @@ func outputItems(f *os.File, items ...string) { } } } + +// returns the list of expanded IPs of given CIDR list +func getIPList(cidrs []*net.IPNet) []net.IP { + var ipList []net.IP + for _, cidr := range cidrs { + ips, err := mapcidr.IPAddressesAsStream(cidr.String()) + if err != nil { + gologger.Fatal().Msgf("%s\n", err) + } + for ip := range ips { + ipList = append(ipList, net.ParseIP(ip)) + } + } + return ipList +} diff --git a/cmd/mapcidr/main_test.go b/cmd/mapcidr/main_test.go index 74c9fd9d..34f895b0 100644 --- a/cmd/mapcidr/main_test.go +++ b/cmd/mapcidr/main_test.go @@ -166,6 +166,60 @@ func TestProcess(t *testing.T) { Aggregate: true, }, expectedOutput: []string{"166.8.0.0/24"}, + }, { + name: "IPsSortAscending", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + FileCidr: []string{"1.1.1.1", "8.8.8.8", "255.255.255.255", "2.2.2.2", "2.4.4.4", "2.4.3.2", "9.9.9.9"}, + SortAscending: true, + }, + expectedOutput: []string{"1.1.1.1", "2.2.2.2", "2.4.3.2", "2.4.4.4", "8.8.8.8", "9.9.9.9", "255.255.255.255"}, + }, { + name: "IPsSortDescending", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + FileCidr: []string{"1.1.1.1", "255.255.255.255", "2.4.3.2", "2.2.2.2", "8.8.8.8", "2.4.4.4", "9.9.9.9"}, + SortDescending: true, + }, + expectedOutput: []string{"255.255.255.255", "9.9.9.9", "8.8.8.8", "2.4.4.4", "2.4.3.2", "2.2.2.2", "1.1.1.1"}, + }, { + name: "CIDRsIPSortAscending", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + FileCidr: []string{"10.40.0.0/30"}, + SortAscending: true, + }, + expectedOutput: []string{"10.40.0.0", "10.40.0.1", "10.40.0.2", "10.40.0.3"}, + }, { + name: "CIDRsIPSortDescending", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + FileCidr: []string{"10.40.1.0/30"}, + SortDescending: true, + }, + expectedOutput: []string{"10.40.1.3", "10.40.1.2", "10.40.1.1", "10.40.1.0"}, + }, { + name: "IPRangeIPSortAscending", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + FileCidr: []string{"192.168.0.0-192.168.0.3"}, + SortAscending: true, + }, + expectedOutput: []string{"192.168.0.0", "192.168.0.1", "192.168.0.2", "192.168.0.3"}, + }, { + name: "IPRangeIIPSortDescending", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + FileCidr: []string{"192.168.1.0-192.168.1.3"}, + SortDescending: true, + }, + expectedOutput: []string{"192.168.1.3", "192.168.1.2", "192.168.1.1", "192.168.1.0"}, }, } var wg sync.WaitGroup From 5ae2e96d2a414364dccb92ddcb27b0d549d325e8 Mon Sep 17 00:00:00 2001 From: Shubham Rasal Date: Wed, 28 Sep 2022 21:39:33 +0530 Subject: [PATCH 3/5] Add integration test cases for mapcidr (#106) * Add IP range input support (ipv4, ipv6) #98 - Update main.go to accept IP range from stdin and print the possible CIDRs * Add test cases to validate RangeTOCIDR function - Add test case for singleCIDR, multipleCIDRs and ip6 range. - Convert the []net.IPNet to []string before comparing the expected. * Add check to validate the IP range and Update README - Accept the list of IP ranges - Fatal() if the first IP is greater than last IP - Fatal() if IP range contains more than 2 values. - Update README.md to add the ip range input documentation. * Update IP range functionality to accept only single range - Remove the unnecessary for loop. - Update the READ.md to remove the IP range list block * Remove the IP comparing logic to a function - Add new function `GetCIDRFromIPRange` which validate the input If input is wrong send the error otherwise returns the sorted list of CIDR ranges. - Update the test case to test `GetCIDRFromIPRange` function. - Add the wrong input IP range test case. - Remove the IP comparing and sorting logic from main.go * Remove the typo * Update code to handle the IP range expansion - Update the `main.go` to handle the case to IP range expansion - rename the `CIDRFromIPRange` to `IPRangeInput` - Add the if block which handles the case when Input is IP range. * Remove old cidrs before appending new cidrs in allCidrs * Move logic to common function to avoid repetition. Do not overwrite allCidrs list instead use a separate net.IP list. * Add tests for process function, * Break wg.Add(2) into two wg.Add(1) * Make wg.Done as defer * Handle case of multiple IP range, combination of CIDR and IP range - Input may contain the multiple CIDRs and multiple IP ranges eg. `166.8.0.0/16,166.11.0.0/16,166.9.0.0-166.10.255.255` - Handle the above input for arggregation, count, etc - Move the string split logic from `main()` to `process()` function - Add the new variable IPRangeMap which stores multiple IP range * Add the comment for ipRange block * Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. Replace ipRangeMap to ipRangeList. - map key is not being used so dropped the map implementation. * Add integration test cases [WIP] - add integration testcases - update the go version in go.mod to 1.18 for slice package * Resolve the requested changes - Remove the IPRangeInput variable - Simplify checking len of IPRange Input - Use require package for checking expected and got in test cases * Replace string.Equal to require package for testing * Add integration tests - Add case for CIDR skip base and broadcast - Add case for CIDR sorting - Add case for IPRange skip base and broadcast * Add go test and integration test in github workflow * Add input file for integration test * solve the lint error * Update the go version in lint workflow * Update the .gitignore for integration-test * Update goflags version - mapcidr and goflag had conflicting version to solve that update the goflags version * Update sorting behaviour - Expand the CIDR then sort - Before it was converting IPs to CIDR then sort. - Add `getIPList()` which expands the CIDRs to IP for sorting * Remove the unnecessary err block * Add integration tests for sorting * Add shuffle & output test case - Add integration test to check the shuffling ips - Add intergration test to check output file functionality * move rm command at the end of script * Resolve requested changes Co-authored-by: Sandeep Singh Co-authored-by: Jaideep Khandelwal Co-authored-by: Siddharth Shashikar <60960197+shashikarsiddharth@users.noreply.github.com> --- .github/workflows/build-test.yml | 10 ++ .github/workflows/lint-test.yml | 2 +- .gitignore | 9 +- cmd/integration-test/goldenfiles/cidrs_a.txt | 4 + cmd/integration-test/goldenfiles/ip_cidr.txt | 4 + .../goldenfiles/ip_list_to_filter.txt | 2 + .../goldenfiles/ip_list_to_match.txt | 2 + cmd/integration-test/goldenfiles/ips_aa.txt | 3 + cmd/integration-test/goldenfiles/ips_sort.txt | 7 + cmd/integration-test/integration-test.go | 37 +++++ cmd/integration-test/mapcidr.go | 132 ++++++++++++++++++ cmd/integration-test/utils.go | 35 +++++ go.mod | 3 +- go.sum | 2 + integration_tests/run.sh | 23 +++ 15 files changed, 271 insertions(+), 4 deletions(-) create mode 100644 cmd/integration-test/goldenfiles/cidrs_a.txt create mode 100644 cmd/integration-test/goldenfiles/ip_cidr.txt create mode 100644 cmd/integration-test/goldenfiles/ip_list_to_filter.txt create mode 100644 cmd/integration-test/goldenfiles/ip_list_to_match.txt create mode 100644 cmd/integration-test/goldenfiles/ips_aa.txt create mode 100644 cmd/integration-test/goldenfiles/ips_sort.txt create mode 100644 cmd/integration-test/integration-test.go create mode 100644 cmd/integration-test/mapcidr.go create mode 100644 cmd/integration-test/utils.go create mode 100644 integration_tests/run.sh diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 363b92e3..599eccb6 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -22,6 +22,16 @@ jobs: run: go build . working-directory: cmd/mapcidr/ + - name: Test + run: go test ./... + working-directory: . + + - name: Integration Tests + env: + GH_ACTION: true + run: bash run.sh + working-directory: integration_tests/ + - name: Race Test run: go run -race . -cidr 192.168.1.224/30 working-directory: cmd/mapcidr/ \ No newline at end of file diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index ae9264dc..8700160f 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -12,7 +12,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.17 + go-version: 1.18 - name: Checkout code uses: actions/checkout@v3 - name: Run golangci-lint diff --git a/.gitignore b/.gitignore index d0303d03..604ee66f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ - +.vscode +mapcidr cmd/mapcidr/mapcidr -.vscode \ No newline at end of file +cmd/integration-test/mapcidr +cmd/integration-test/integration-test +integration_tests/mapcidr +integration_tests/goldenfiles +integration_tests/integration-test diff --git a/cmd/integration-test/goldenfiles/cidrs_a.txt b/cmd/integration-test/goldenfiles/cidrs_a.txt new file mode 100644 index 00000000..69ce5eb2 --- /dev/null +++ b/cmd/integration-test/goldenfiles/cidrs_a.txt @@ -0,0 +1,4 @@ +173.0.0.0/18 +173.0.64.0/18 +173.0.128.0/18 +173.0.192.0/18 diff --git a/cmd/integration-test/goldenfiles/ip_cidr.txt b/cmd/integration-test/goldenfiles/ip_cidr.txt new file mode 100644 index 00000000..b4d46383 --- /dev/null +++ b/cmd/integration-test/goldenfiles/ip_cidr.txt @@ -0,0 +1,4 @@ +166.8.0.0/16 +166.9.0.0-166.9.255.255 +166.10.0.0/16 +166.11.0.0-166.11.255.255 diff --git a/cmd/integration-test/goldenfiles/ip_list_to_filter.txt b/cmd/integration-test/goldenfiles/ip_list_to_filter.txt new file mode 100644 index 00000000..da5533f7 --- /dev/null +++ b/cmd/integration-test/goldenfiles/ip_list_to_filter.txt @@ -0,0 +1,2 @@ +192.168.1.1 +192.168.1.3 diff --git a/cmd/integration-test/goldenfiles/ip_list_to_match.txt b/cmd/integration-test/goldenfiles/ip_list_to_match.txt new file mode 100644 index 00000000..c242e4bc --- /dev/null +++ b/cmd/integration-test/goldenfiles/ip_list_to_match.txt @@ -0,0 +1,2 @@ +192.168.1.253 +192.168.1.252 diff --git a/cmd/integration-test/goldenfiles/ips_aa.txt b/cmd/integration-test/goldenfiles/ips_aa.txt new file mode 100644 index 00000000..33254188 --- /dev/null +++ b/cmd/integration-test/goldenfiles/ips_aa.txt @@ -0,0 +1,3 @@ +1.1.1.1 +1.1.1.16 +1.1.1.31 diff --git a/cmd/integration-test/goldenfiles/ips_sort.txt b/cmd/integration-test/goldenfiles/ips_sort.txt new file mode 100644 index 00000000..e7b517bc --- /dev/null +++ b/cmd/integration-test/goldenfiles/ips_sort.txt @@ -0,0 +1,7 @@ +1.1.1.1 +8.8.8.8 +255.255.255.255 +2.2.2.2 +2.4.4.4 +2.4.3.2 +9.9.9.9 diff --git a/cmd/integration-test/integration-test.go b/cmd/integration-test/integration-test.go new file mode 100644 index 00000000..8d88d8de --- /dev/null +++ b/cmd/integration-test/integration-test.go @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "os" + "strings" + + "github.com/logrusorgru/aurora" +) + +var ( + debug = os.Getenv("DEBUG") == "true" + customTest = os.Getenv("TEST") + errored = false +) + +func main() { + success := aurora.Green("[✓]").String() + failed := aurora.Red("[✘]").String() + + for name, testCase := range mapcidrTestcases { + if customTest != "" && !strings.Contains(name, customTest) { + continue // only run tests user asked + } + fmt.Printf("Running test cases for \"%s\"\n", aurora.Cyan(name)) + err := testCase.Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, name, err) + errored = true + } else { + fmt.Printf("%s Test \"%s\" passed!\n", success, name) + } + } + if errored { + os.Exit(1) + } +} diff --git a/cmd/integration-test/mapcidr.go b/cmd/integration-test/mapcidr.go new file mode 100644 index 00000000..da4e229e --- /dev/null +++ b/cmd/integration-test/mapcidr.go @@ -0,0 +1,132 @@ +package main + +import ( + "fmt" + "io/ioutil" + "strings" + + "golang.org/x/exp/slices" +) + +type TestCase interface { + // Execute executes a test case and returns any errors if occurred + Execute() error +} + +type mapCidrQuery struct { + question string + args string + expectedOutput []string +} + +type mapCidrQueryOutputFile struct { + question string + args string + expectedOutput []string + outputfile string +} + +var mapcidrTestcases = map[string]TestCase{ + // CIDR + "CIDR Exapansion": &mapCidrQuery{question: "192.168.0.0/30", expectedOutput: []string{"192.168.0.0", "192.168.0.1", "192.168.0.2", "192.168.0.3"}}, + "Multiple CIDR Exapansion": &mapCidrQuery{question: "192.168.0.0/30,10.50.0.0/30", expectedOutput: []string{"192.168.0.0", "192.168.0.1", "192.168.0.2", "192.168.0.3", "10.50.0.0", "10.50.0.1", "10.50.0.2", "10.50.0.3"}}, + "Slice CIDRs by given CIDR count": &mapCidrQuery{question: "173.0.84.0/24", expectedOutput: []string{"173.0.84.0/27", "173.0.84.32/27", "173.0.84.64/27", "173.0.84.96/27", "173.0.84.128/27", "173.0.84.160/27", "173.0.84.208/28", "173.0.84.192/28", "173.0.84.240/28", "173.0.84.224/28"}, args: "-sbc 10"}, + "Slice CIDRs by given host count": &mapCidrQuery{question: "173.0.0.0/16", expectedOutput: []string{"173.0.0.0/18", "173.0.64.0/18", "173.0.128.0/18", "173.0.192.0/18"}, args: "-sbh 20000"}, + "CIDR Arggregation": &mapCidrQuery{question: "173.0.0.0/18,173.0.64.0/18,173.0.128.0/18,173.0.192.0/18", expectedOutput: []string{"173.0.0.0/16"}, args: "-a"}, + "CIDR Arggregation(file)": &mapCidrQuery{question: "", expectedOutput: []string{"173.0.0.0/16"}, args: "-cl ./goldenfiles/cidrs_a.txt -a"}, + "CIDR Appox Arggregation(file)": &mapCidrQuery{question: "", expectedOutput: []string{"1.1.1.0/27"}, args: "-cl ./goldenfiles/ips_aa.txt -aa"}, + "CIDR IP Count": &mapCidrQuery{question: "173.0.84.0/24,10.0.0.0/24", expectedOutput: []string{"512"}, args: "-c"}, + "Match IP's(args) from CIDR": &mapCidrQuery{question: "192.168.1.0/24", expectedOutput: []string{"192.168.1.253", "192.168.1.252"}, args: "-mi 192.168.1.253,192.168.1.252"}, + "Match IP's(file) from CIDR": &mapCidrQuery{question: "192.168.1.0/24", expectedOutput: []string{"192.168.1.253", "192.168.1.252"}, args: "-mi ./goldenfiles/ip_list_to_match.txt"}, + "Filter IP's(args) from CIDR": &mapCidrQuery{question: "192.168.1.0/30", expectedOutput: []string{"192.168.1.0", "192.168.1.2"}, args: "-fi 192.168.1.1,192.168.1.3"}, + "Filter IP's(file) from CIDR": &mapCidrQuery{question: "192.168.1.0/30", expectedOutput: []string{"192.168.1.0", "192.168.1.2"}, args: "-fi ./goldenfiles/ip_list_to_filter.txt"}, + "Convert IPs to IPv6": &mapCidrQuery{question: "192.168.0.0/30", expectedOutput: []string{"00:00:00:00:00:ffff:c0a8:0000", "00:00:00:00:00:ffff:c0a8:0001", "00:00:00:00:00:ffff:c0a8:0002", "00:00:00:00:00:ffff:c0a8:0003"}, args: "-t6"}, + "CIDR Skip Base": &mapCidrQuery{question: "192.168.1.0/30", expectedOutput: []string{"192.168.1.1", "192.168.1.2", "192.168.1.3"}, args: "-skip-base"}, + "CIDR Skip Broadcast": &mapCidrQuery{question: "192.168.0.255/30", expectedOutput: []string{"192.168.0.252", "192.168.0.253", "192.168.0.254"}, args: "-skip-broadcast"}, + "CIDR Sort (ascending order)": &mapCidrQuery{question: "192.168.0.0/30", expectedOutput: []string{"192.168.0.0", "192.168.0.1", "192.168.0.2", "192.168.0.3"}, args: "-s"}, + "CIDR Reverse Sort (descending order)": &mapCidrQuery{question: "10.40.1.0/30", expectedOutput: []string{"10.40.1.3", "10.40.1.2", "10.40.1.1", "10.40.1.0"}, args: "-sr"}, + "CIDR Shuffle IPs": &mapCidrQuery{question: "192.168.0.0/30", expectedOutput: []string{"192.168.0.3", "192.168.0.0", "192.168.0.1", "192.168.0.2"}, args: "-si"}, + "CIDR Shuffle Port IPs": &mapCidrQuery{question: "192.168.0.0/30", expectedOutput: []string{"192.168.0.3:8080", "192.168.0.0:8080", "192.168.0.1:8080", "192.168.0.2:8080"}, args: "-sp 8080"}, + "CIDR Shuffle Multiple Port IPs": &mapCidrQuery{question: "192.168.0.0/30", expectedOutput: []string{"192.168.0.3:8080", "192.168.0.0:8080", "192.168.0.1:8080", "192.168.0.2:8080", "192.168.0.3:9090", "192.168.0.0:9090", "192.168.0.1:9090", "192.168.0.2:9090"}, args: "-sp 8080,9090"}, + + //IP range + "IPRange Exapansion": &mapCidrQuery{question: "192.168.0.0-192.168.0.3", expectedOutput: []string{"192.168.0.0", "192.168.0.1", "192.168.0.2", "192.168.0.3"}}, + "Multiple IPRange Exapansion": &mapCidrQuery{question: "192.168.0.0-192.168.0.3,192.168.0.4-192.168.0.10", expectedOutput: []string{"192.168.0.0", "192.168.0.1", "192.168.0.2", "192.168.0.3", "192.168.0.4", "192.168.0.5", "192.168.0.6", "192.168.0.7", "192.168.0.8", "192.168.0.9", "192.168.0.10"}}, + "IPRange Aggregation": &mapCidrQuery{question: "192.168.0.0-192.168.0.3", expectedOutput: []string{"192.168.0.0/30"}, args: "-a"}, + "Multiple IPRange Aggregation": &mapCidrQuery{question: "192.168.0.0-192.168.0.128,192.168.0.129-192.168.0.255", expectedOutput: []string{"192.168.0.0/24"}, args: "-a"}, + "IPRange IP count": &mapCidrQuery{question: "192.168.0.0-192.168.0.255", expectedOutput: []string{"256"}, args: "-c"}, + "Match IP's(args) from IPRange": &mapCidrQuery{question: "192.168.0.0-192.168.0.3", expectedOutput: []string{"192.168.0.1", "192.168.0.3"}, args: "-mi 192.168.0.1,192.168.0.3"}, + "Filter IP's(file) from IPRange": &mapCidrQuery{question: "192.168.0.0-192.168.0.3", expectedOutput: []string{"192.168.0.0", "192.168.0.2"}, args: "-fi 192.168.0.1,192.168.0.3"}, + "Convert IPs to IPv6 from IPRange": &mapCidrQuery{question: "192.168.0.0-192.168.0.3", expectedOutput: []string{"00:00:00:00:00:ffff:c0a8:0000", "00:00:00:00:00:ffff:c0a8:0001", "00:00:00:00:00:ffff:c0a8:0002", "00:00:00:00:00:ffff:c0a8:0003"}, args: "-t6"}, + "Slice IPRange by given CIDR count": &mapCidrQuery{question: "173.0.84.0-173.0.84.255", expectedOutput: []string{"173.0.84.0/27", "173.0.84.32/27", "173.0.84.64/27", "173.0.84.96/27", "173.0.84.128/27", "173.0.84.160/27", "173.0.84.208/28", "173.0.84.192/28", "173.0.84.240/28", "173.0.84.224/28"}, args: "-sbc 10"}, + "Slice IPRange by given host count": &mapCidrQuery{question: "173.0.0.0-173.0.255.255", expectedOutput: []string{"173.0.0.0/18", "173.0.64.0/18", "173.0.128.0/18", "173.0.192.0/18"}, args: "-sbh 20000"}, + "IPRange Skip Base": &mapCidrQuery{question: "192.168.0.0-192.168.0.3", expectedOutput: []string{"192.168.0.1", "192.168.0.2", "192.168.0.3"}, args: "-skip-base"}, + "IPRange Skip Broadcast": &mapCidrQuery{question: "192.168.0.252-192.168.0.255", expectedOutput: []string{"192.168.0.252", "192.168.0.253", "192.168.0.254"}, args: "-skip-broadcast"}, + "IPRange Sort (ascending order)": &mapCidrQuery{question: "192.168.0.0-192.168.0.3", expectedOutput: []string{"192.168.0.0", "192.168.0.1", "192.168.0.2", "192.168.0.3"}, args: "-s"}, + "IPRange Reverse Sort (descending order)": &mapCidrQuery{question: "192.168.1.0-192.168.1.3", expectedOutput: []string{"192.168.1.3", "192.168.1.2", "192.168.1.1", "192.168.1.0"}, args: "-sr"}, + "IPRange Shuffle IPs": &mapCidrQuery{question: "192.168.0.0-192.168.0.3", expectedOutput: []string{"192.168.0.3", "192.168.0.0", "192.168.0.1", "192.168.0.2"}, args: "-si"}, + "IPRange Shuffle Port IPs": &mapCidrQuery{question: "173.0.0.0-173.0.0.3", expectedOutput: []string{"173.0.0.3:8080", "173.0.0.0:8080", "173.0.0.1:8080", "173.0.0.2:8080"}, args: "-sp 8080"}, + "IPRange Shuffle Multiple Port IPs": &mapCidrQuery{question: "192.168.0.0-192.168.0.3", expectedOutput: []string{"192.168.0.3:8080", "192.168.0.0:8080", "192.168.0.1:8080", "192.168.0.2:8080", "192.168.0.3:9090", "192.168.0.0:9090", "192.168.0.1:9090", "192.168.0.2:9090"}, args: "-sp 8080,9090"}, + + // sort IPs from file + "IPs Sort (ascending order)": &mapCidrQuery{question: "", expectedOutput: []string{"1.1.1.1", "2.2.2.2", "2.4.3.2", "2.4.4.4", "8.8.8.8", "9.9.9.9", "255.255.255.255"}, args: "-cl ./goldenfiles/ips_sort.txt -s"}, + "IPs Sort (descending order)": &mapCidrQuery{question: "", expectedOutput: []string{"255.255.255.255", "9.9.9.9", "8.8.8.8", "2.4.4.4", "2.4.3.2", "2.2.2.2", "1.1.1.1"}, args: "-cl ./goldenfiles/ips_sort.txt -s"}, + + // combination of IPRange and CIDRs + "IPRange & CIDR Aggregation": &mapCidrQuery{question: "166.8.0.0/16,166.11.0.0/16,166.9.0.0-166.10.255.255", expectedOutput: []string{"166.8.0.0/14"}, args: "-a"}, + "IPRange & CIDR Aggregation(file)": &mapCidrQuery{question: "", expectedOutput: []string{"166.8.0.0/14"}, args: "-cl ./goldenfiles/ip_cidr.txt -a"}, + "IPRange & CIDR Expansion": &mapCidrQuery{question: "192.168.0.0/30,192.168.0.4-192.168.0.10", expectedOutput: []string{"192.168.0.0", "192.168.0.1", "192.168.0.2", "192.168.0.3", "192.168.0.4", "192.168.0.5", "192.168.0.6", "192.168.0.7", "192.168.0.8", "192.168.0.9", "192.168.0.10"}}, + "IPRange & CIDR Count": &mapCidrQuery{question: "166.8.0.0/16,166.11.0.0/16,166.9.0.0-166.10.255.255", expectedOutput: []string{"262144"}, args: "-c"}, + "IPRange & CIDR convert IPs to IPv6": &mapCidrQuery{question: "192.168.0.0-192.168.0.3", expectedOutput: []string{"00:00:00:00:00:ffff:c0a8:0000", "00:00:00:00:00:ffff:c0a8:0001", "00:00:00:00:00:ffff:c0a8:0002", "00:00:00:00:00:ffff:c0a8:0003"}, args: "-t6"}, + + "OutputFile case": &mapCidrQueryOutputFile{question: "192.168.0.0/30", expectedOutput: []string{"192.168.0.0", "192.168.0.1", "192.168.0.2", "192.168.0.3"}, args: "-o /tmp/output.txt", outputfile: "/tmp/output.txt"}, +} + +func (h *mapCidrQuery) Execute() error { + result, err := RunMapCidrAndGetResults(h.question, debug, h.args) + if err != nil { + return err + } + return compareResult(h.expectedOutput, result) +} + +func (h *mapCidrQueryOutputFile) Execute() error { + _, err := RunMapCidrAndGetResults(h.question, debug, h.args) + if err != nil { + return err + } + // read output file and compare result + fileContent, err := ioutil.ReadFile(h.outputfile) + if err != nil { + return err + } + result := []string{} + items := strings.Split(string(fileContent), "\n") + for _, i := range items { + if i != "" { + result = append(result, i) + } + } + return compareResult(h.expectedOutput, result) +} + +func errIncorrectResultsCount(results []string) error { + return fmt.Errorf("incorrect number of results %s", strings.Join(results, "\n\t")) +} + +func errIncorrectResult(expected, got []string) error { + return fmt.Errorf("incorrect result: expected \"%s\" got \"%s\"", expected, got) +} + +func compareResult(expected, result []string) error { + // check if incorrent number of result + if len(result) != len(expected) { + return errIncorrectResultsCount(result) + } + for _, v := range result { + if !slices.Contains(expected, v) { + return errIncorrectResult(expected, result) + } + } + return nil +} diff --git a/cmd/integration-test/utils.go b/cmd/integration-test/utils.go new file mode 100644 index 00000000..ddaf3487 --- /dev/null +++ b/cmd/integration-test/utils.go @@ -0,0 +1,35 @@ +package main + +import ( + "os" + "os/exec" + "strings" +) + +// RunMapCidrAndGetResults returns a list of results +func RunMapCidrAndGetResults(question string, debug bool, extra ...string) ([]string, error) { + cmd := exec.Command("bash", "-c") + cmdLine := `echo "` + question + `" | ./mapcidr ` + cmdLine += strings.Join(extra, " ") + if debug { + cmdLine += " -debug" + cmd.Stderr = os.Stderr + } else { + cmdLine += " -silent" + } + + cmd.Args = append(cmd.Args, cmdLine) + + data, err := cmd.Output() + if err != nil { + return nil, err + } + parts := []string{} + items := strings.Split(string(data), "\n") + for _, i := range items { + if i != "" { + parts = append(parts, i) + } + } + return parts, nil +} diff --git a/go.mod b/go.mod index 72d398fa..e290f131 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/projectdiscovery/mapcidr go 1.18 require ( + github.com/logrusorgru/aurora v2.0.3+incompatible github.com/pkg/errors v0.9.1 github.com/projectdiscovery/blackrock v0.0.0-20220628111055-35616c71b2dc github.com/projectdiscovery/fileutil v0.0.0-20220705195237-01becc2a8963 @@ -12,6 +13,7 @@ require ( github.com/projectdiscovery/sliceutil v0.0.0-20220625085859-c3a4ecb669f4 github.com/projectdiscovery/stringsutil v0.0.1 github.com/stretchr/testify v1.8.0 + golang.org/x/exp v0.0.0-20220907003533-145caa8ea1d0 ) require ( @@ -22,7 +24,6 @@ require ( github.com/golang/snappy v0.0.3 // indirect github.com/gorilla/css v1.0.0 // indirect github.com/json-iterator/go v1.1.11 // indirect - github.com/logrusorgru/aurora v2.0.3+incompatible // indirect github.com/microcosm-cc/bluemonday v1.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect diff --git a/go.sum b/go.sum index 1ce88de6..5a62acaf 100644 --- a/go.sum +++ b/go.sum @@ -109,6 +109,8 @@ go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= +golang.org/x/exp v0.0.0-20220907003533-145caa8ea1d0 h1:17k44ji3KFYG94XS5QEFC8pyuOlMh3IoR+vkmTZmJJs= +golang.org/x/exp v0.0.0-20220907003533-145caa8ea1d0/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220617184016-355a448f1bc9/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= diff --git a/integration_tests/run.sh b/integration_tests/run.sh new file mode 100644 index 00000000..42d108d0 --- /dev/null +++ b/integration_tests/run.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +echo "::group::Build mapcidr" +cd ../cmd/mapcidr +go build +mv mapcidr ../../integration_tests/mapcidr +echo "::endgroup::" +echo "::group::Build mapcidr integration-test" +cd ../integration-test +go build +cp -rf goldenfiles ../../integration_tests/ +mv integration-test ../../integration_tests/integration-test +cd ../../integration_tests +echo "::endgroup::" +./integration-test +if [ $? -eq 0 ] +then + rm integration-test mapcidr 2>/dev/null + exit 0 +else + rm integration-test mapcidr 2>/dev/null + exit 1 +fi From 0b134e77d807af10b08e1b77e381db69d044c59b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 Oct 2022 17:37:39 +0530 Subject: [PATCH 4/5] chore(deps): bump golang from 1.19.1-alpine to 1.19.2-alpine (#111) Bumps golang from 1.19.1-alpine to 1.19.2-alpine. --- updated-dependencies: - dependency-name: golang dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 67ebb786..7a37ea56 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19.1-alpine AS build-env +FROM golang:1.19.2-alpine AS build-env RUN go install -v github.com/projectdiscovery/mapcidr/cmd/mapcidr@latest FROM alpine:latest From a54aa5b9c7000e94497063fbef7336ea8f417277 Mon Sep 17 00:00:00 2001 From: Shubham Rasal Date: Wed, 12 Oct 2022 13:50:37 +0530 Subject: [PATCH 5/5] add asn support (#112) * version update * add asnmap * Create a sample package for mapcidr to call asnmap * Add AS input support issue #110 - Add asn package to resolve import cycle error. - Accept the ASN number input support to mapcidr. eg. `echo AS15133 | mapcidr` - Create the asnmap client to query for CIDRs. * Resolve requested changes. * update readme * add test case for testing streaming IP * add goldenfiles for testing * update the goldenfile path Co-authored-by: Sandeep Singh Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com> Co-authored-by: Jaideep K --- README.md | 13 + asn/asn.go | 69 +++++ asn/asn_test.go | 82 ++++++ asn/goldenfiles/AS134029.txt | 512 +++++++++++++++++++++++++++++++++++ asn/goldenfiles/AS14421.txt | 256 ++++++++++++++++++ cmd/mapcidr/main.go | 34 ++- go.mod | 16 +- go.sum | 53 ++++ 8 files changed, 1025 insertions(+), 10 deletions(-) create mode 100644 asn/asn.go create mode 100644 asn/asn_test.go create mode 100644 asn/goldenfiles/AS134029.txt create mode 100644 asn/goldenfiles/AS14421.txt diff --git a/README.md b/README.md index db9a3f62..3341e55c 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,19 @@ $ echo 173.0.84.0/16 | mapcidr -count -silent 65536 ``` +### ASN Input + +In order to get the IP address of ASN number, use the following command +``` +echo AS15133 | mapcidr -silent + +5.104.64.0 +5.104.64.1 +5.104.64.2 +5.104.64.3 +5.104.64.4 +``` + # Use mapCIDR as a library It's possible to use the library directly in your go programs. The following code snippets outline how to divide a cidr into subnets, and how to divide the same into subnets containing a certain number of hosts diff --git a/asn/asn.go b/asn/asn.go new file mode 100644 index 00000000..2ccbf4ef --- /dev/null +++ b/asn/asn.go @@ -0,0 +1,69 @@ +package asn + +import ( + "fmt" + "net" + "strconv" + "strings" + + asnmap "github.com/projectdiscovery/asnmap/libs" + "github.com/projectdiscovery/mapcidr" +) + +type ASNClient struct { + client *asnmap.Client +} + +func New() ASNClient { + return ASNClient{ + client: asnmap.NewClient(), + } +} + +// GetCIDRsForASNNum returns the slice of cidrs for given ASN number +// accept the ASN number like 'AS15133' and returns the CIDRs for that ASN +func (c *ASNClient) GetCIDRsForASNNum(value string) ([]*net.IPNet, error) { + var cidrs []*net.IPNet + if len(value) < 3 { + return nil, fmt.Errorf("invalid asn number %s", value) + } + // drop the AS suffix + asn := asnmap.ASN(value[2:]) + for _, cidr := range asnmap.GetCIDR(c.client.GetData(asn)) { + // filter IPv6 CIDR + if mapcidr.IsIPv4(cidr.IP) { + cidrs = append(cidrs, cidr) + } + } + return cidrs, nil +} + +// GetIPAddressesAsStream returns the chan of IP address for given ASN number +// returning the string chan for optimizing the memory +func (c *ASNClient) GetIPAddressesAsStream(value string) (chan string, error) { + cidrs, err := c.GetCIDRsForASNNum(value) + if err != nil { + return nil, err + } + ret := make(chan string) + go func() { + defer close(ret) + for _, cidr := range cidrs { + ips, _ := mapcidr.IPAddressesAsStream(cidr.String()) + for ip := range ips { + ret <- ip + } + } + }() + return ret, nil +} + +// IsASN checks if the given input is ASN or not, +// its possible to have an domain name starting with AS/as prefix. +func IsASN(value string) bool { + if len(value) > 2 && strings.HasPrefix(strings.ToUpper(value), "AS") { + _, err := strconv.Atoi(value[2:]) + return err == nil + } + return false +} diff --git a/asn/asn_test.go b/asn/asn_test.go new file mode 100644 index 00000000..c65328c0 --- /dev/null +++ b/asn/asn_test.go @@ -0,0 +1,82 @@ +package asn + +import ( + "io/ioutil" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func Test_asnClient_GetCIDRsForASNNum(t *testing.T) { + tests := []struct { + name string + asnNumber string + expected []string + }{ + { + name: "ASN Number 1", + asnNumber: "AS14421", + expected: []string{"216.101.17.0/24"}, + }, + { + name: "ASN Number 2", + asnNumber: "AS7712", + expected: []string{"118.67.200.0/23", "118.67.202.0/24", "118.67.203.0/24", "118.67.204.0/22"}, + }, + { + name: "Wrong ASN number", + asnNumber: "AS", + expected: []string{}, + }, + } + asnClient := New() + + for _, tt := range tests { + var result []string + got, err := asnClient.GetCIDRsForASNNum(tt.asnNumber) + if err != nil { + require.ErrorContains(t, err, "invalid asn number") + } + for _, cidr := range got { + result = append(result, cidr.String()) + } + require.ElementsMatch(t, tt.expected, result, "could not get correct cidrs") + } +} + +func TestASNClient_GetIPAddressesAsStream(t *testing.T) { + tests := []struct { + name string + asnNumber string + expectedOutputFile string + }{ + { + name: "ASN Number 1", + asnNumber: "AS14421", + expectedOutputFile: "goldenfiles/AS14421.txt", + }, + { + name: "ASN Number 2", + asnNumber: "AS134029", + expectedOutputFile: "goldenfiles/AS134029.txt", + }, + } + asnClient := New() + for _, tt := range tests { + var result []string + got, err := asnClient.GetIPAddressesAsStream(tt.asnNumber) + if err != nil { + require.ErrorContains(t, err, "invalid asn number") + } + for ip := range got { + result = append(result, ip) + } + // read the expectedOutputFile + fileContent, err := ioutil.ReadFile(tt.expectedOutputFile) + require.Nil(t, err, "could not read the expectedOutputFile file") + items := strings.Split(string(fileContent), "\n") + + require.ElementsMatch(t, items, result, "could not get correct cidrs") + } +} diff --git a/asn/goldenfiles/AS134029.txt b/asn/goldenfiles/AS134029.txt new file mode 100644 index 00000000..23954861 --- /dev/null +++ b/asn/goldenfiles/AS134029.txt @@ -0,0 +1,512 @@ +103.57.226.0 +103.57.226.1 +103.57.226.2 +103.57.226.3 +103.57.226.4 +103.57.226.5 +103.57.226.6 +103.57.226.7 +103.57.226.8 +103.57.226.9 +103.57.226.10 +103.57.226.11 +103.57.226.12 +103.57.226.13 +103.57.226.14 +103.57.226.15 +103.57.226.16 +103.57.226.17 +103.57.226.18 +103.57.226.19 +103.57.226.20 +103.57.226.21 +103.57.226.22 +103.57.226.23 +103.57.226.24 +103.57.226.25 +103.57.226.26 +103.57.226.27 +103.57.226.28 +103.57.226.29 +103.57.226.30 +103.57.226.31 +103.57.226.32 +103.57.226.33 +103.57.226.34 +103.57.226.35 +103.57.226.36 +103.57.226.37 +103.57.226.38 +103.57.226.39 +103.57.226.40 +103.57.226.41 +103.57.226.42 +103.57.226.43 +103.57.226.44 +103.57.226.45 +103.57.226.46 +103.57.226.47 +103.57.226.48 +103.57.226.49 +103.57.226.50 +103.57.226.51 +103.57.226.52 +103.57.226.53 +103.57.226.54 +103.57.226.55 +103.57.226.56 +103.57.226.57 +103.57.226.58 +103.57.226.59 +103.57.226.60 +103.57.226.61 +103.57.226.62 +103.57.226.63 +103.57.226.64 +103.57.226.65 +103.57.226.66 +103.57.226.67 +103.57.226.68 +103.57.226.69 +103.57.226.70 +103.57.226.71 +103.57.226.72 +103.57.226.73 +103.57.226.74 +103.57.226.75 +103.57.226.76 +103.57.226.77 +103.57.226.78 +103.57.226.79 +103.57.226.80 +103.57.226.81 +103.57.226.82 +103.57.226.83 +103.57.226.84 +103.57.226.85 +103.57.226.86 +103.57.226.87 +103.57.226.88 +103.57.226.89 +103.57.226.90 +103.57.226.91 +103.57.226.92 +103.57.226.93 +103.57.226.94 +103.57.226.95 +103.57.226.96 +103.57.226.97 +103.57.226.98 +103.57.226.99 +103.57.226.100 +103.57.226.101 +103.57.226.102 +103.57.226.103 +103.57.226.104 +103.57.226.105 +103.57.226.106 +103.57.226.107 +103.57.226.108 +103.57.226.109 +103.57.226.110 +103.57.226.111 +103.57.226.112 +103.57.226.113 +103.57.226.114 +103.57.226.115 +103.57.226.116 +103.57.226.117 +103.57.226.118 +103.57.226.119 +103.57.226.120 +103.57.226.121 +103.57.226.122 +103.57.226.123 +103.57.226.124 +103.57.226.125 +103.57.226.126 +103.57.226.127 +103.57.226.128 +103.57.226.129 +103.57.226.130 +103.57.226.131 +103.57.226.132 +103.57.226.133 +103.57.226.134 +103.57.226.135 +103.57.226.136 +103.57.226.137 +103.57.226.138 +103.57.226.139 +103.57.226.140 +103.57.226.141 +103.57.226.142 +103.57.226.143 +103.57.226.144 +103.57.226.145 +103.57.226.146 +103.57.226.147 +103.57.226.148 +103.57.226.149 +103.57.226.150 +103.57.226.151 +103.57.226.152 +103.57.226.153 +103.57.226.154 +103.57.226.155 +103.57.226.156 +103.57.226.157 +103.57.226.158 +103.57.226.159 +103.57.226.160 +103.57.226.161 +103.57.226.162 +103.57.226.163 +103.57.226.164 +103.57.226.165 +103.57.226.166 +103.57.226.167 +103.57.226.168 +103.57.226.169 +103.57.226.170 +103.57.226.171 +103.57.226.172 +103.57.226.173 +103.57.226.174 +103.57.226.175 +103.57.226.176 +103.57.226.177 +103.57.226.178 +103.57.226.179 +103.57.226.180 +103.57.226.181 +103.57.226.182 +103.57.226.183 +103.57.226.184 +103.57.226.185 +103.57.226.186 +103.57.226.187 +103.57.226.188 +103.57.226.189 +103.57.226.190 +103.57.226.191 +103.57.226.192 +103.57.226.193 +103.57.226.194 +103.57.226.195 +103.57.226.196 +103.57.226.197 +103.57.226.198 +103.57.226.199 +103.57.226.200 +103.57.226.201 +103.57.226.202 +103.57.226.203 +103.57.226.204 +103.57.226.205 +103.57.226.206 +103.57.226.207 +103.57.226.208 +103.57.226.209 +103.57.226.210 +103.57.226.211 +103.57.226.212 +103.57.226.213 +103.57.226.214 +103.57.226.215 +103.57.226.216 +103.57.226.217 +103.57.226.218 +103.57.226.219 +103.57.226.220 +103.57.226.221 +103.57.226.222 +103.57.226.223 +103.57.226.224 +103.57.226.225 +103.57.226.226 +103.57.226.227 +103.57.226.228 +103.57.226.229 +103.57.226.230 +103.57.226.231 +103.57.226.232 +103.57.226.233 +103.57.226.234 +103.57.226.235 +103.57.226.236 +103.57.226.237 +103.57.226.238 +103.57.226.239 +103.57.226.240 +103.57.226.241 +103.57.226.242 +103.57.226.243 +103.57.226.244 +103.57.226.245 +103.57.226.246 +103.57.226.247 +103.57.226.248 +103.57.226.249 +103.57.226.250 +103.57.226.251 +103.57.226.252 +103.57.226.253 +103.57.226.254 +103.57.226.255 +103.58.114.0 +103.58.114.1 +103.58.114.2 +103.58.114.3 +103.58.114.4 +103.58.114.5 +103.58.114.6 +103.58.114.7 +103.58.114.8 +103.58.114.9 +103.58.114.10 +103.58.114.11 +103.58.114.12 +103.58.114.13 +103.58.114.14 +103.58.114.15 +103.58.114.16 +103.58.114.17 +103.58.114.18 +103.58.114.19 +103.58.114.20 +103.58.114.21 +103.58.114.22 +103.58.114.23 +103.58.114.24 +103.58.114.25 +103.58.114.26 +103.58.114.27 +103.58.114.28 +103.58.114.29 +103.58.114.30 +103.58.114.31 +103.58.114.32 +103.58.114.33 +103.58.114.34 +103.58.114.35 +103.58.114.36 +103.58.114.37 +103.58.114.38 +103.58.114.39 +103.58.114.40 +103.58.114.41 +103.58.114.42 +103.58.114.43 +103.58.114.44 +103.58.114.45 +103.58.114.46 +103.58.114.47 +103.58.114.48 +103.58.114.49 +103.58.114.50 +103.58.114.51 +103.58.114.52 +103.58.114.53 +103.58.114.54 +103.58.114.55 +103.58.114.56 +103.58.114.57 +103.58.114.58 +103.58.114.59 +103.58.114.60 +103.58.114.61 +103.58.114.62 +103.58.114.63 +103.58.114.64 +103.58.114.65 +103.58.114.66 +103.58.114.67 +103.58.114.68 +103.58.114.69 +103.58.114.70 +103.58.114.71 +103.58.114.72 +103.58.114.73 +103.58.114.74 +103.58.114.75 +103.58.114.76 +103.58.114.77 +103.58.114.78 +103.58.114.79 +103.58.114.80 +103.58.114.81 +103.58.114.82 +103.58.114.83 +103.58.114.84 +103.58.114.85 +103.58.114.86 +103.58.114.87 +103.58.114.88 +103.58.114.89 +103.58.114.90 +103.58.114.91 +103.58.114.92 +103.58.114.93 +103.58.114.94 +103.58.114.95 +103.58.114.96 +103.58.114.97 +103.58.114.98 +103.58.114.99 +103.58.114.100 +103.58.114.101 +103.58.114.102 +103.58.114.103 +103.58.114.104 +103.58.114.105 +103.58.114.106 +103.58.114.107 +103.58.114.108 +103.58.114.109 +103.58.114.110 +103.58.114.111 +103.58.114.112 +103.58.114.113 +103.58.114.114 +103.58.114.115 +103.58.114.116 +103.58.114.117 +103.58.114.118 +103.58.114.119 +103.58.114.120 +103.58.114.121 +103.58.114.122 +103.58.114.123 +103.58.114.124 +103.58.114.125 +103.58.114.126 +103.58.114.127 +103.58.114.128 +103.58.114.129 +103.58.114.130 +103.58.114.131 +103.58.114.132 +103.58.114.133 +103.58.114.134 +103.58.114.135 +103.58.114.136 +103.58.114.137 +103.58.114.138 +103.58.114.139 +103.58.114.140 +103.58.114.141 +103.58.114.142 +103.58.114.143 +103.58.114.144 +103.58.114.145 +103.58.114.146 +103.58.114.147 +103.58.114.148 +103.58.114.149 +103.58.114.150 +103.58.114.151 +103.58.114.152 +103.58.114.153 +103.58.114.154 +103.58.114.155 +103.58.114.156 +103.58.114.157 +103.58.114.158 +103.58.114.159 +103.58.114.160 +103.58.114.161 +103.58.114.162 +103.58.114.163 +103.58.114.164 +103.58.114.165 +103.58.114.166 +103.58.114.167 +103.58.114.168 +103.58.114.169 +103.58.114.170 +103.58.114.171 +103.58.114.172 +103.58.114.173 +103.58.114.174 +103.58.114.175 +103.58.114.176 +103.58.114.177 +103.58.114.178 +103.58.114.179 +103.58.114.180 +103.58.114.181 +103.58.114.182 +103.58.114.183 +103.58.114.184 +103.58.114.185 +103.58.114.186 +103.58.114.187 +103.58.114.188 +103.58.114.189 +103.58.114.190 +103.58.114.191 +103.58.114.192 +103.58.114.193 +103.58.114.194 +103.58.114.195 +103.58.114.196 +103.58.114.197 +103.58.114.198 +103.58.114.199 +103.58.114.200 +103.58.114.201 +103.58.114.202 +103.58.114.203 +103.58.114.204 +103.58.114.205 +103.58.114.206 +103.58.114.207 +103.58.114.208 +103.58.114.209 +103.58.114.210 +103.58.114.211 +103.58.114.212 +103.58.114.213 +103.58.114.214 +103.58.114.215 +103.58.114.216 +103.58.114.217 +103.58.114.218 +103.58.114.219 +103.58.114.220 +103.58.114.221 +103.58.114.222 +103.58.114.223 +103.58.114.224 +103.58.114.225 +103.58.114.226 +103.58.114.227 +103.58.114.228 +103.58.114.229 +103.58.114.230 +103.58.114.231 +103.58.114.232 +103.58.114.233 +103.58.114.234 +103.58.114.235 +103.58.114.236 +103.58.114.237 +103.58.114.238 +103.58.114.239 +103.58.114.240 +103.58.114.241 +103.58.114.242 +103.58.114.243 +103.58.114.244 +103.58.114.245 +103.58.114.246 +103.58.114.247 +103.58.114.248 +103.58.114.249 +103.58.114.250 +103.58.114.251 +103.58.114.252 +103.58.114.253 +103.58.114.254 +103.58.114.255 \ No newline at end of file diff --git a/asn/goldenfiles/AS14421.txt b/asn/goldenfiles/AS14421.txt new file mode 100644 index 00000000..3d78092c --- /dev/null +++ b/asn/goldenfiles/AS14421.txt @@ -0,0 +1,256 @@ +216.101.17.0 +216.101.17.1 +216.101.17.2 +216.101.17.3 +216.101.17.4 +216.101.17.5 +216.101.17.6 +216.101.17.7 +216.101.17.8 +216.101.17.9 +216.101.17.10 +216.101.17.11 +216.101.17.12 +216.101.17.13 +216.101.17.14 +216.101.17.15 +216.101.17.16 +216.101.17.17 +216.101.17.18 +216.101.17.19 +216.101.17.20 +216.101.17.21 +216.101.17.22 +216.101.17.23 +216.101.17.24 +216.101.17.25 +216.101.17.26 +216.101.17.27 +216.101.17.28 +216.101.17.29 +216.101.17.30 +216.101.17.31 +216.101.17.32 +216.101.17.33 +216.101.17.34 +216.101.17.35 +216.101.17.36 +216.101.17.37 +216.101.17.38 +216.101.17.39 +216.101.17.40 +216.101.17.41 +216.101.17.42 +216.101.17.43 +216.101.17.44 +216.101.17.45 +216.101.17.46 +216.101.17.47 +216.101.17.48 +216.101.17.49 +216.101.17.50 +216.101.17.51 +216.101.17.52 +216.101.17.53 +216.101.17.54 +216.101.17.55 +216.101.17.56 +216.101.17.57 +216.101.17.58 +216.101.17.59 +216.101.17.60 +216.101.17.61 +216.101.17.62 +216.101.17.63 +216.101.17.64 +216.101.17.65 +216.101.17.66 +216.101.17.67 +216.101.17.68 +216.101.17.69 +216.101.17.70 +216.101.17.71 +216.101.17.72 +216.101.17.73 +216.101.17.74 +216.101.17.75 +216.101.17.76 +216.101.17.77 +216.101.17.78 +216.101.17.79 +216.101.17.80 +216.101.17.81 +216.101.17.82 +216.101.17.83 +216.101.17.84 +216.101.17.85 +216.101.17.86 +216.101.17.87 +216.101.17.88 +216.101.17.89 +216.101.17.90 +216.101.17.91 +216.101.17.92 +216.101.17.93 +216.101.17.94 +216.101.17.95 +216.101.17.96 +216.101.17.97 +216.101.17.98 +216.101.17.99 +216.101.17.100 +216.101.17.101 +216.101.17.102 +216.101.17.103 +216.101.17.104 +216.101.17.105 +216.101.17.106 +216.101.17.107 +216.101.17.108 +216.101.17.109 +216.101.17.110 +216.101.17.111 +216.101.17.112 +216.101.17.113 +216.101.17.114 +216.101.17.115 +216.101.17.116 +216.101.17.117 +216.101.17.118 +216.101.17.119 +216.101.17.120 +216.101.17.121 +216.101.17.122 +216.101.17.123 +216.101.17.124 +216.101.17.125 +216.101.17.126 +216.101.17.127 +216.101.17.128 +216.101.17.129 +216.101.17.130 +216.101.17.131 +216.101.17.132 +216.101.17.133 +216.101.17.134 +216.101.17.135 +216.101.17.136 +216.101.17.137 +216.101.17.138 +216.101.17.139 +216.101.17.140 +216.101.17.141 +216.101.17.142 +216.101.17.143 +216.101.17.144 +216.101.17.145 +216.101.17.146 +216.101.17.147 +216.101.17.148 +216.101.17.149 +216.101.17.150 +216.101.17.151 +216.101.17.152 +216.101.17.153 +216.101.17.154 +216.101.17.155 +216.101.17.156 +216.101.17.157 +216.101.17.158 +216.101.17.159 +216.101.17.160 +216.101.17.161 +216.101.17.162 +216.101.17.163 +216.101.17.164 +216.101.17.165 +216.101.17.166 +216.101.17.167 +216.101.17.168 +216.101.17.169 +216.101.17.170 +216.101.17.171 +216.101.17.172 +216.101.17.173 +216.101.17.174 +216.101.17.175 +216.101.17.176 +216.101.17.177 +216.101.17.178 +216.101.17.179 +216.101.17.180 +216.101.17.181 +216.101.17.182 +216.101.17.183 +216.101.17.184 +216.101.17.185 +216.101.17.186 +216.101.17.187 +216.101.17.188 +216.101.17.189 +216.101.17.190 +216.101.17.191 +216.101.17.192 +216.101.17.193 +216.101.17.194 +216.101.17.195 +216.101.17.196 +216.101.17.197 +216.101.17.198 +216.101.17.199 +216.101.17.200 +216.101.17.201 +216.101.17.202 +216.101.17.203 +216.101.17.204 +216.101.17.205 +216.101.17.206 +216.101.17.207 +216.101.17.208 +216.101.17.209 +216.101.17.210 +216.101.17.211 +216.101.17.212 +216.101.17.213 +216.101.17.214 +216.101.17.215 +216.101.17.216 +216.101.17.217 +216.101.17.218 +216.101.17.219 +216.101.17.220 +216.101.17.221 +216.101.17.222 +216.101.17.223 +216.101.17.224 +216.101.17.225 +216.101.17.226 +216.101.17.227 +216.101.17.228 +216.101.17.229 +216.101.17.230 +216.101.17.231 +216.101.17.232 +216.101.17.233 +216.101.17.234 +216.101.17.235 +216.101.17.236 +216.101.17.237 +216.101.17.238 +216.101.17.239 +216.101.17.240 +216.101.17.241 +216.101.17.242 +216.101.17.243 +216.101.17.244 +216.101.17.245 +216.101.17.246 +216.101.17.247 +216.101.17.248 +216.101.17.249 +216.101.17.250 +216.101.17.251 +216.101.17.252 +216.101.17.253 +216.101.17.254 +216.101.17.255 \ No newline at end of file diff --git a/cmd/mapcidr/main.go b/cmd/mapcidr/main.go index b4502624..9c5e57e7 100644 --- a/cmd/mapcidr/main.go +++ b/cmd/mapcidr/main.go @@ -18,6 +18,7 @@ import ( "github.com/projectdiscovery/gologger/levels" "github.com/projectdiscovery/ipranger" "github.com/projectdiscovery/mapcidr" + asn "github.com/projectdiscovery/mapcidr/asn" "github.com/projectdiscovery/sliceutil" ) @@ -287,12 +288,14 @@ func prepareIPsFromCidrFlagList(items []string) []string { func process(wg *sync.WaitGroup, chancidr, outputchan chan string) { defer wg.Done() var ( - allCidrs []*net.IPNet - pCidr *net.IPNet - ranger *ipranger.IPRanger - err error - hasSort = options.SortAscending || options.SortDescending - ipRangeList = make([][]net.IP, 0) + allCidrs []*net.IPNet + pCidr *net.IPNet + ranger *ipranger.IPRanger + err error + hasSort = options.SortAscending || options.SortDescending + ipRangeList = make([][]net.IP, 0) + asnNumberList []string + asnClient = asn.New() ) ranger, _ = ipranger.New() @@ -312,6 +315,11 @@ func process(wg *sync.WaitGroup, chancidr, outputchan chan string) { ipRangeList = append(ipRangeList, ipRange) continue } + // Add ASN number + if asn.IsASN(cidr) { + asnNumberList = append(asnNumberList, cidr) + continue + } // if it's an ip turn it into a cidr if ip := net.ParseIP(cidr); ip != nil { switch { @@ -358,6 +366,20 @@ func process(wg *sync.WaitGroup, chancidr, outputchan chan string) { } } + for _, asnNumber := range asnNumberList { + cidrs, err := asnClient.GetCIDRsForASNNum(asnNumber) + if err != nil { + gologger.Fatal().Msgf("%s\n", err) + } + if options.Aggregate || options.Shuffle || hasSort || options.AggregateApprox || options.Count { + allCidrs = append(allCidrs, cidrs...) + } else { + for _, cidr := range cidrs { + commonFunc(cidr.String(), outputchan) + } + } + } + // Shuffle perform the aggregation if options.Shuffle { var ports []int diff --git a/go.mod b/go.mod index e290f131..02fa1149 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,10 @@ go 1.18 require ( github.com/logrusorgru/aurora v2.0.3+incompatible github.com/pkg/errors v0.9.1 + github.com/projectdiscovery/asnmap v0.0.1 github.com/projectdiscovery/blackrock v0.0.0-20220628111055-35616c71b2dc - github.com/projectdiscovery/fileutil v0.0.0-20220705195237-01becc2a8963 - github.com/projectdiscovery/goflags v0.0.10-0.20220912115102-d9ea875a0a6a + github.com/projectdiscovery/fileutil v0.0.1 + github.com/projectdiscovery/goflags v0.1.0 github.com/projectdiscovery/gologger v1.1.4 github.com/projectdiscovery/ipranger v0.0.3 github.com/projectdiscovery/sliceutil v0.0.0-20220625085859-c3a4ecb669f4 @@ -25,17 +26,24 @@ require ( github.com/gorilla/css v1.0.0 // indirect github.com/json-iterator/go v1.1.11 // indirect github.com/microcosm-cc/bluemonday v1.0.20 // indirect + github.com/miekg/dns v1.1.50 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/projectdiscovery/hmap v0.0.1 // indirect - github.com/projectdiscovery/iputil v0.0.0-20220625072148-037479960416 // indirect + github.com/projectdiscovery/iputil v0.0.0-20220712175312-b9406f31cdd8 // indirect github.com/projectdiscovery/networkpolicy v0.0.2-0.20220525172507-b844eafc878d // indirect + github.com/projectdiscovery/retryabledns v1.0.15 // indirect + github.com/projectdiscovery/retryablehttp-go v1.0.2 // indirect github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect github.com/syndtr/goleveldb v1.0.0 // indirect github.com/yl2chen/cidranger v1.0.2 // indirect - go.uber.org/atomic v1.7.0 // indirect + go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.8.0 // indirect + golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect + golang.org/x/sys v0.0.0-20220731174439-a90be440212d // indirect + golang.org/x/text v0.3.7 // indirect + golang.org/x/tools v0.1.12 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 5a62acaf..60c39b49 100644 --- a/go.sum +++ b/go.sum @@ -33,8 +33,11 @@ github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQ github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/microcosm-cc/bluemonday v1.0.18/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM= +github.com/microcosm-cc/bluemonday v1.0.19/go.mod h1:QNzV2UbLK2/53oIIwTOyLUSABMkjZ4tqiyC1g/DyqxE= github.com/microcosm-cc/bluemonday v1.0.20 h1:flpzsq4KU3QIYAYGV/szUat7H+GPOXR0B2JU5A1Wp8Y= github.com/microcosm-cc/bluemonday v1.0.20/go.mod h1:yfBmMi8mxvaZut3Yytv+jTXRY8mxyjJ0/kQBTElld50= +github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA= +github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -50,6 +53,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/projectdiscovery/asnmap v0.0.1 h1:n4YCz1ljUaDA3dOUCkjI/bUOtiS7ge1KJ39qpURCd/o= +github.com/projectdiscovery/asnmap v0.0.1/go.mod h1:CjCVDhQPVtmlE247L6YFeIVX9c4m8pOX8V8BmB0JkX8= github.com/projectdiscovery/blackrock v0.0.0-20210415162320-b38689ae3a2e/go.mod h1:/IsapnEYiWG+yEDPXp0e8NWj3npzB9Ccy9lXEUJwMZs= github.com/projectdiscovery/blackrock v0.0.0-20210903102120-5a9d2412d21d/go.mod h1:/IsapnEYiWG+yEDPXp0e8NWj3npzB9Ccy9lXEUJwMZs= github.com/projectdiscovery/blackrock v0.0.0-20220628111055-35616c71b2dc h1:jqZK68yPOnNNRmwuXqytl+T9EbwneEUCvMDRjLe0J04= @@ -59,10 +64,14 @@ github.com/projectdiscovery/fileutil v0.0.0-20220506114156-c4ab20801483/go.mod h github.com/projectdiscovery/fileutil v0.0.0-20220609150212-453ac591c36c/go.mod h1:g8wsrb0S5NtEN0JgVyyPeb3FQdArx+UMESmFX94bcGY= github.com/projectdiscovery/fileutil v0.0.0-20220705195237-01becc2a8963 h1:4o97N9ftX1J3iKlIRVMPVOVZs4qbCczJvoFF2WA40t4= github.com/projectdiscovery/fileutil v0.0.0-20220705195237-01becc2a8963/go.mod h1:DaY7wmLPMleyHDCD/14YApPCDtrARY4J8Eny2ZGsG/g= +github.com/projectdiscovery/fileutil v0.0.1 h1:3K3UqCDOan3LsvWhV0nyvVuMWSwCloNPUJIGcXsi1os= +github.com/projectdiscovery/fileutil v0.0.1/go.mod h1:Oo6ZEvXmQz/xPF0YukzmwpdW2LYinWCSEmzZOQsJCLg= github.com/projectdiscovery/goflags v0.0.8-0.20220426153734-2ffbfbff923c/go.mod h1:uN+pHMLsWQoiZHUg/l0tqf/VdbX3+ecKfYz/H7b/+NA= github.com/projectdiscovery/goflags v0.0.8/go.mod h1:GDSkWyXa6kfQjpJu10SO64DN8lXuKXVENlBMk8N7H80= github.com/projectdiscovery/goflags v0.0.10-0.20220912115102-d9ea875a0a6a h1:m/eXb33ECH86slvT09YFTmuMqPMIAIloODHjW2bTeNY= github.com/projectdiscovery/goflags v0.0.10-0.20220912115102-d9ea875a0a6a/go.mod h1:/YBPA+1igSkQbwD7a91o0HUIwMDlsmQDRZL2oSYSyEQ= +github.com/projectdiscovery/goflags v0.1.0 h1:Z7sUVK8wgH6aGJWinmGQEtsn+GNf/0RQ+z1wQcpCeeA= +github.com/projectdiscovery/goflags v0.1.0/go.mod h1:/YBPA+1igSkQbwD7a91o0HUIwMDlsmQDRZL2oSYSyEQ= github.com/projectdiscovery/gologger v1.0.1/go.mod h1:Ok+axMqK53bWNwDSU1nTNwITLYMXMdZtRc8/y1c7sWE= github.com/projectdiscovery/gologger v1.1.4 h1:qWxGUq7ukHWT849uGPkagPKF3yBPYAsTtMKunQ8O2VI= github.com/projectdiscovery/gologger v1.1.4/go.mod h1:Bhb6Bdx2PV1nMaFLoXNBmHIU85iROS9y1tBuv7T5pMY= @@ -74,18 +83,25 @@ github.com/projectdiscovery/ipranger v0.0.3/go.mod h1:pb7qOZyXI6n9Z5izLZmkTiunaB github.com/projectdiscovery/iputil v0.0.0-20210414194613-4b4d2517acf0/go.mod h1:PQAqn5h5NXsQTF4ZA00ZTYLRzGCjOtcCq8llAqrsd1A= github.com/projectdiscovery/iputil v0.0.0-20220625072148-037479960416 h1:gShD8T2jtK3p78cabXa9fWBCHFgZ6BGJwoounugKeIQ= github.com/projectdiscovery/iputil v0.0.0-20220625072148-037479960416/go.mod h1:bst7imnXn0ckAw4sToXLHLm62HisFGnS4QlxOkE4mYQ= +github.com/projectdiscovery/iputil v0.0.0-20220712175312-b9406f31cdd8 h1:HRqev12wKvcwK1fe4pSlMfQdPHo9LfTxuFeRN4f3tS4= +github.com/projectdiscovery/iputil v0.0.0-20220712175312-b9406f31cdd8/go.mod h1:vHRC+9exsfSbEngMKDl0xiWqkxlLk3lHQZpbS2yFT8U= github.com/projectdiscovery/mapcidr v0.0.4/go.mod h1:ALOIj6ptkWujNoX8RdQwB2mZ+kAmKuLJBq9T5gR5wG0= github.com/projectdiscovery/mapcidr v0.0.6/go.mod h1:ZEBhMmBU3laUl3g9QGTrzJku1VJOzjdFwW01f/zVVzM= github.com/projectdiscovery/mapcidr v1.0.0/go.mod h1:5QkKrV6rNQQurCZI3nNedFsAOYp04mRDkC5yht+znYA= github.com/projectdiscovery/mapcidr v1.0.1/go.mod h1:/qxlpxXZQFFjHynSc9u5O0kUPzH46VskECiwLiz7/vw= github.com/projectdiscovery/networkpolicy v0.0.2-0.20220525172507-b844eafc878d h1:QXaK3yzoEWI8n+hLAqEgTJEWhkp1WZM8ThbKwrlXFks= github.com/projectdiscovery/networkpolicy v0.0.2-0.20220525172507-b844eafc878d/go.mod h1:asvdg5wMy3LPVMGALatebKeOYH5n5fV5RCTv6DbxpIs= +github.com/projectdiscovery/retryabledns v1.0.15 h1:3Nn119UwYsfUPC3g0q57ftz0Wb5Zl5ppvw8R0Xu0DEI= +github.com/projectdiscovery/retryabledns v1.0.15/go.mod h1:3YbsQVqP7jbQ3CDmarhyVtkJaJ8XcB7S19vMeyMxZxk= +github.com/projectdiscovery/retryablehttp-go v1.0.2 h1:LV1/KAQU+yeWhNVlvveaYFsjBYRwXlNEq0PvrezMV0U= +github.com/projectdiscovery/retryablehttp-go v1.0.2/go.mod h1:dx//aY9V247qHdsRf0vdWHTBZuBQ2vm6Dq5dagxrDYI= github.com/projectdiscovery/sliceutil v0.0.0-20220617151003-15892688e1d6/go.mod h1:9YZb6LRjLYAvSOm65v787dwauurixSyjlqXyYa4rTTA= github.com/projectdiscovery/sliceutil v0.0.0-20220625085859-c3a4ecb669f4 h1:C04j5gVVMXqFyBIetAz92SyPRYCpkFgIwZw0L/pps9Q= github.com/projectdiscovery/sliceutil v0.0.0-20220625085859-c3a4ecb669f4/go.mod h1:RxDaccMjPzIuF7F8XbdGl1yOcqxN4YPiHr9xHpfCkGI= github.com/projectdiscovery/stringsutil v0.0.0-20210804142656-fd3c28dbaafe/go.mod h1:oTRc18WBv9t6BpaN9XBY+QmG28PUpsyDzRht56Qf49I= github.com/projectdiscovery/stringsutil v0.0.0-20220422150559-b54fb5dc6833/go.mod h1:oTRc18WBv9t6BpaN9XBY+QmG28PUpsyDzRht56Qf49I= github.com/projectdiscovery/stringsutil v0.0.0-20220612082425-0037ce9f89f3/go.mod h1:mF5sh4jTghoGWwgUb9qWi5waTFklClDbtrqtJU93awc= +github.com/projectdiscovery/stringsutil v0.0.0-20220731064040-4b67f194751e/go.mod h1:32NYmKyHkKsmisAOAaWrR15lz2ysz2M8x3KMeeoRHoU= github.com/projectdiscovery/stringsutil v0.0.1 h1:a6TCMT+D1aUsoZxNiYf9O30wiDOoLOHDwj89HBjr5BQ= github.com/projectdiscovery/stringsutil v0.0.1/go.mod h1:TDi2LEqR3OML0BxGoMbbfAHSk5AdfHX762Oc302sgmM= github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca h1:NugYot0LIVPxTvN8n+Kvkn6TrbMyxQiuvKdEwFdR9vI= @@ -105,33 +121,70 @@ github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFd github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/yl2chen/cidranger v1.0.2 h1:lbOWZVCG1tCRX4u24kuM1Tb4nHqWkDxwLdoS+SevawU= github.com/yl2chen/cidranger v1.0.2/go.mod h1:9U1yz7WPYDwf0vpNWFaeRh0bjwz5RVgRy/9UEQfHl0g= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20220907003533-145caa8ea1d0 h1:17k44ji3KFYG94XS5QEFC8pyuOlMh3IoR+vkmTZmJJs= golang.org/x/exp v0.0.0-20220907003533-145caa8ea1d0/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210521195947-fe42d452be8f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220617184016-355a448f1bc9/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.0.0-20220728211354-c7608f3a8462/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.0.0-20220909164309-bea034e7d591 h1:D0B/7al0LLrVC8aWF4+oxpv/m8bc7ViFfVS8/gXGdqI= golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220731174439-a90be440212d h1:Sv5ogFZatcgIMMtBSTTAgMYsicp25MXBubjXNDKwm80= +golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=