From 93bd8f49fdbce52731699f4dbb406726d70b8d17 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Jul 2022 21:30:44 +0000 Subject: [PATCH 01/12] chore(deps): bump golang from 1.18.3-alpine to 1.18.4-alpine Bumps golang from 1.18.3-alpine to 1.18.4-alpine. --- updated-dependencies: - dependency-name: golang dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 37bf48c..b531771 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.18.3-alpine AS build-env +FROM golang:1.18.4-alpine AS build-env RUN go install -v github.com/projectdiscovery/mapcidr/cmd/mapcidr@latest FROM alpine:latest From ce320f3a50cb944348c31b7689e05bb6df79d0bc Mon Sep 17 00:00:00 2001 From: sandeep Date: Sat, 23 Jul 2022 17:03:36 +0530 Subject: [PATCH 02/12] Added release announce automation --- .github/workflows/release-binary.yml | 20 +++++++++++--------- .goreleaser.yml | 9 ++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release-binary.yml b/.github/workflows/release-binary.yml index 516442a..893aa60 100644 --- a/.github/workflows/release-binary.yml +++ b/.github/workflows/release-binary.yml @@ -1,4 +1,5 @@ name: 🎉 Release Binary + on: create: tags: @@ -8,23 +9,24 @@ on: jobs: release: runs-on: ubuntu-latest - steps: - - - name: "Check out code" + steps: + - name: "Check out code" uses: actions/checkout@v3 with: fetch-depth: 0 - - - name: "Set up Go" + + - name: "Set up Go" uses: actions/setup-go@v3 - with: + with: go-version: 1.18 - - - env: + + - env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + SLACK_WEBHOOK: "${{ secrets.RELEASE_SLACK_WEBHOOK }}" + name: "Create release on GitHub" uses: goreleaser/goreleaser-action@v3 - with: + with: args: "release --rm-dist" version: latest workdir: . \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml index 68b233c..ae0d4bf 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -18,4 +18,11 @@ archives: darwin: macOS format_overrides: - goos: windows - format: zip \ No newline at end of file + format: zip + +announce: + slack: + enabled: true + channel: '#release' + username: GoReleaser + message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}' \ No newline at end of file From 406cd9b5939c4676bd00d8b7b9feaf86b7c365f4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Jul 2022 21:08:34 +0000 Subject: [PATCH 03/12] chore(deps): bump github.com/projectdiscovery/goflags Bumps [github.com/projectdiscovery/goflags](https://github.com/projectdiscovery/goflags) from 0.0.8 to 0.0.9. - [Release notes](https://github.com/projectdiscovery/goflags/releases) - [Commits](https://github.com/projectdiscovery/goflags/compare/v0.0.8...v0.0.9) --- updated-dependencies: - dependency-name: github.com/projectdiscovery/goflags dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c004aa4..ff93e0c 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/projectdiscovery/blackrock v0.0.0-20210415162320-b38689ae3a2e github.com/projectdiscovery/fileutil v0.0.0-20220609150212-453ac591c36c - github.com/projectdiscovery/goflags v0.0.8 + github.com/projectdiscovery/goflags v0.0.9 github.com/projectdiscovery/gologger v1.1.4 github.com/projectdiscovery/ipranger v0.0.2 github.com/projectdiscovery/sliceutil v0.0.0-20220617151003-15892688e1d6 diff --git a/go.sum b/go.sum index ea3205a..c1920b4 100644 --- a/go.sum +++ b/go.sum @@ -53,8 +53,8 @@ github.com/projectdiscovery/blackrock v0.0.0-20210415162320-b38689ae3a2e/go.mod github.com/projectdiscovery/fileutil v0.0.0-20210928100737-cab279c5d4b5/go.mod h1:U+QCpQnX8o2N2w0VUGyAzjM3yBAe4BKedVElxiImsx0= github.com/projectdiscovery/fileutil v0.0.0-20220609150212-453ac591c36c h1:/+xJK8e/Gj/zAmudWh5l2SzGJB+CkwYnraelCkBe7Aw= github.com/projectdiscovery/fileutil v0.0.0-20220609150212-453ac591c36c/go.mod h1:g8wsrb0S5NtEN0JgVyyPeb3FQdArx+UMESmFX94bcGY= -github.com/projectdiscovery/goflags v0.0.8 h1:IhTmnEGSKtBHfD23tSwpnzai5CRYfLKVOWlVq9ngYvY= -github.com/projectdiscovery/goflags v0.0.8/go.mod h1:GDSkWyXa6kfQjpJu10SO64DN8lXuKXVENlBMk8N7H80= +github.com/projectdiscovery/goflags v0.0.9 h1:bPsYIPE1LvdgYaM3XNX0YmS68e6huv22W22rKh5IscI= +github.com/projectdiscovery/goflags v0.0.9/go.mod h1:t/dEhv2VDOzayugXZCkbkX8n+pPeVmRD+WgQRSgReeI= 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= From a65d14c5333a290534351b96941f3b4bcf8c9c9a Mon Sep 17 00:00:00 2001 From: mzack Date: Tue, 26 Jul 2022 08:44:29 +0200 Subject: [PATCH 04/12] adding error check to flags parse --- cmd/mapcidr/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/mapcidr/main.go b/cmd/mapcidr/main.go index 48147f4..a984387 100644 --- a/cmd/mapcidr/main.go +++ b/cmd/mapcidr/main.go @@ -121,7 +121,9 @@ func ParseOptions() *Options { flagSet.BoolVar(&options.Version, "version", false, "Show version of the project"), ) - _ = flagSet.Parse() + if err := flagSet.Parse(); err != nil { + gologger.Fatal().Msgf("%s\n", err) + } // Read the inputs and configure the logging options.configureOutput() From b80e775cb4324922d7e4434c7290f65b7f469b1d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Aug 2022 21:04:30 +0000 Subject: [PATCH 05/12] chore(deps): bump golang from 1.18.4-alpine to 1.18.5-alpine Bumps golang from 1.18.4-alpine to 1.18.5-alpine. --- updated-dependencies: - dependency-name: golang dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b531771..37c0ff2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.18.4-alpine AS build-env +FROM golang:1.18.5-alpine AS build-env RUN go install -v github.com/projectdiscovery/mapcidr/cmd/mapcidr@latest FROM alpine:latest From edec5fa76ed5ef07cb22c8e47f44d2b303fcb063 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 Aug 2022 21:04:41 +0000 Subject: [PATCH 06/12] chore(deps): bump golang from 1.18.5-alpine to 1.19.0-alpine Bumps golang from 1.18.5-alpine to 1.19.0-alpine. --- updated-dependencies: - dependency-name: golang dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 37c0ff2..97a1a17 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.18.5-alpine AS build-env +FROM golang:1.19.0-alpine AS build-env RUN go install -v github.com/projectdiscovery/mapcidr/cmd/mapcidr@latest FROM alpine:latest From 37cb5ecd8b3a6a06c704fe7b737edc2c14c8df10 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Aug 2022 21:06:35 +0000 Subject: [PATCH 07/12] chore(deps): bump github.com/projectdiscovery/ipranger Bumps [github.com/projectdiscovery/ipranger](https://github.com/projectdiscovery/ipranger) from 0.0.2 to 0.0.3. - [Release notes](https://github.com/projectdiscovery/ipranger/releases) - [Commits](https://github.com/projectdiscovery/ipranger/compare/v0.0.2...v0.0.3) --- updated-dependencies: - dependency-name: github.com/projectdiscovery/ipranger dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 9 ++++++--- go.sum | 22 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index ff93e0c..edb8560 100644 --- a/go.mod +++ b/go.mod @@ -4,11 +4,11 @@ go 1.17 require ( github.com/pkg/errors v0.9.1 - github.com/projectdiscovery/blackrock v0.0.0-20210415162320-b38689ae3a2e + github.com/projectdiscovery/blackrock v0.0.0-20210903102120-5a9d2412d21d github.com/projectdiscovery/fileutil v0.0.0-20220609150212-453ac591c36c github.com/projectdiscovery/goflags v0.0.9 github.com/projectdiscovery/gologger v1.1.4 - github.com/projectdiscovery/ipranger v0.0.2 + github.com/projectdiscovery/ipranger v0.0.3 github.com/projectdiscovery/sliceutil v0.0.0-20220617151003-15892688e1d6 github.com/projectdiscovery/stringsutil v0.0.0-20220612082425-0037ce9f89f3 github.com/stretchr/testify v1.8.0 @@ -28,10 +28,13 @@ require ( 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/networkpolicy v0.0.2-0.20220525172507-b844eafc878d // 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/multierr v1.8.0 // indirect golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index c1920b4..ca9af49 100644 --- a/go.sum +++ b/go.sum @@ -11,6 +11,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -48,11 +49,15 @@ 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/blackrock v0.0.0-20210415162320-b38689ae3a2e h1:7bwaFH1jvtOo5ndhTQgoA349ozhX+1dc4b6tbaPnBOA= github.com/projectdiscovery/blackrock v0.0.0-20210415162320-b38689ae3a2e/go.mod h1:/IsapnEYiWG+yEDPXp0e8NWj3npzB9Ccy9lXEUJwMZs= +github.com/projectdiscovery/blackrock v0.0.0-20210903102120-5a9d2412d21d h1:1Q94movG4VMVo+qf781ttXXt2bxBOIGMenmuCAJDLfE= +github.com/projectdiscovery/blackrock v0.0.0-20210903102120-5a9d2412d21d/go.mod h1:/IsapnEYiWG+yEDPXp0e8NWj3npzB9Ccy9lXEUJwMZs= github.com/projectdiscovery/fileutil v0.0.0-20210928100737-cab279c5d4b5/go.mod h1:U+QCpQnX8o2N2w0VUGyAzjM3yBAe4BKedVElxiImsx0= +github.com/projectdiscovery/fileutil v0.0.0-20220506114156-c4ab20801483/go.mod h1:wjS/oBWbzlayJ/aTK0KW0oOHGO03G8oEYzuN6stI8Ho= github.com/projectdiscovery/fileutil v0.0.0-20220609150212-453ac591c36c h1:/+xJK8e/Gj/zAmudWh5l2SzGJB+CkwYnraelCkBe7Aw= github.com/projectdiscovery/fileutil v0.0.0-20220609150212-453ac591c36c/go.mod h1:g8wsrb0S5NtEN0JgVyyPeb3FQdArx+UMESmFX94bcGY= +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.9 h1:bPsYIPE1LvdgYaM3XNX0YmS68e6huv22W22rKh5IscI= github.com/projectdiscovery/goflags v0.0.9/go.mod h1:t/dEhv2VDOzayugXZCkbkX8n+pPeVmRD+WgQRSgReeI= github.com/projectdiscovery/gologger v1.0.1/go.mod h1:Ok+axMqK53bWNwDSU1nTNwITLYMXMdZtRc8/y1c7sWE= @@ -60,9 +65,18 @@ github.com/projectdiscovery/gologger v1.1.4 h1:qWxGUq7ukHWT849uGPkagPKF3yBPYAsTt github.com/projectdiscovery/gologger v1.1.4/go.mod h1:Bhb6Bdx2PV1nMaFLoXNBmHIU85iROS9y1tBuv7T5pMY= github.com/projectdiscovery/hmap v0.0.1 h1:VAONbJw5jP+syI5smhsfkrq9XPGn4aiYy5pR6KR1wog= github.com/projectdiscovery/hmap v0.0.1/go.mod h1:VDEfgzkKQdq7iGTKz8Ooul0NuYHQ8qiDs6r8bPD1Sb0= -github.com/projectdiscovery/ipranger v0.0.2 h1:5GcKu+4QWNzD38IJZc3mFBrqboDix6cfJkcn2RsJFGM= github.com/projectdiscovery/ipranger v0.0.2/go.mod h1:kcAIk/lo5rW+IzUrFkeYyXnFJ+dKwYooEOHGVPP/RWE= +github.com/projectdiscovery/ipranger v0.0.3 h1:U60Dp6gHJ08PLMsKAWzHlnjE+8q01BhnUiDfjAjc7Gk= +github.com/projectdiscovery/ipranger v0.0.3/go.mod h1:pb7qOZyXI6n9Z5izLZmkTiunaBBbdqYEh6+y435b6CU= +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/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/sliceutil v0.0.0-20220617151003-15892688e1d6 h1:zZmLOwj2duDafEO9i1KqmHMW0SL9+Wwmco9sxhBCVwQ= github.com/projectdiscovery/sliceutil v0.0.0-20220617151003-15892688e1d6/go.mod h1:9YZb6LRjLYAvSOm65v787dwauurixSyjlqXyYa4rTTA= github.com/projectdiscovery/stringsutil v0.0.0-20210804142656-fd3c28dbaafe/go.mod h1:oTRc18WBv9t6BpaN9XBY+QmG28PUpsyDzRht56Qf49I= @@ -85,6 +99,10 @@ 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= +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/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 h1:Yqz/iviulwKwAREEeUd3nbBFn0XuyJqkoft2IlrvOhc= From b3ac7013d37bb2271c00ccd8ba4c4ae876e565a7 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Mon, 29 Aug 2022 22:40:43 +0200 Subject: [PATCH 08/12] fixing compilation error --- cmd/mapcidr/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/mapcidr/main.go b/cmd/mapcidr/main.go index a984387..6f2be9e 100644 --- a/cmd/mapcidr/main.go +++ b/cmd/mapcidr/main.go @@ -318,7 +318,7 @@ func process(wg *sync.WaitGroup, chancidr, outputchan chan string) { // In case of coalesce/shuffle we need to know all the cidrs and aggregate them by calling the proper function if options.Aggregate || options.Shuffle || hasSort || options.AggregateApprox || options.Count { - _ = ranger.AddIPNet(pCidr) + _ = ranger.Add(cidr) allCidrs = append(allCidrs, pCidr) } else if options.Slices > 0 { subnets, err := mapcidr.SplitN(cidr, options.Slices) From cc692284be25fd6e0c741854050695cf5da73323 Mon Sep 17 00:00:00 2001 From: Shubham Rasal Date: Mon, 12 Sep 2022 11:10:37 +0530 Subject: [PATCH 09/12] Add IP range input support (ipv4, ipv6) (#99) * 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 Co-authored-by: Sandeep Singh Co-authored-by: Jaideep Khandelwal Co-authored-by: Siddharth Shashikar <60960197+shashikarsiddharth@users.noreply.github.com> --- README.md | 29 ++++++ cmd/mapcidr/main.go | 100 +++++++++++++------ cmd/mapcidr/main_test.go | 201 +++++++++++++++++++++++++++++++++++++++ ip.go | 16 ++++ ip_test.go | 56 +++++++++++ 5 files changed, 372 insertions(+), 30 deletions(-) create mode 100644 cmd/mapcidr/main_test.go diff --git a/README.md b/README.md index 54a3165..db9a3f6 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,18 @@ mapcidr -cidr 173.0.84.0/24 173.0.84.16 ``` +It is also possible to get list of IP's for a given IP range, use the following command +```console +$ echo "192.168.0.0-192.168.0.5" | mapcidr +``` +```console +192.168.0.0 +192.168.0.1 +192.168.0.2 +192.168.0.3 +192.168.0.4 +192.168.0.5 +``` ### CIDR Slicing by CIDR Count In order to slice given CIDR or list of CIDR by CIDR count or slice into multiple and equal smaller subnets, use the following command. @@ -199,6 +211,23 @@ $ cat ips.txt | mapcidr -aggregate-approx 1.1.1.0/27 ``` +In order to list CIDR blocks for given IP Range (**IPv4 | IPv6**), use the following command. +``` + $ mapcidr -cl 192.168.0.1-192.168.0.255 -aggregate + OR + $ echo 192.168.0.1-192.168.0.255 | mapcidr -aggregate +``` +``` +192.168.0.1/32 +192.168.0.2/31 +192.168.0.4/30 +192.168.0.8/29 +192.168.0.16/28 +192.168.0.32/27 +192.168.0.64/26 +192.168.0.128/25 + +``` ### Match / Filter IP's from CIDR In order to match IPs from the given list of CIDR ranges, use the following command. diff --git a/cmd/mapcidr/main.go b/cmd/mapcidr/main.go index 6f2be9e..5a3de16 100644 --- a/cmd/mapcidr/main.go +++ b/cmd/mapcidr/main.go @@ -283,16 +283,31 @@ 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 + allCidrs []*net.IPNet + pCidr *net.IPNet + ranger *ipranger.IPRanger + err error + hasSort = options.SortAscending || options.SortDescending + ipRangeList = make([][]net.IP, 0) ) ranger, _ = ipranger.New() for cidr := range chancidr { + + // Add IPs into ipRangeList which are passed as input. Example - "192.168.0.0-192.168.0.5" + if strings.Contains(cidr, "-") { + var ipRange []net.IP + for _, ipstr := range strings.Split(cidr, "-") { + ipRange = append(ipRange, net.ParseIP(ipstr)) + } + //check if ipRange has more than 2 values + if len(ipRange) > 2 { + gologger.Fatal().Msgf("IP range can not have more than 2 values.") + } + ipRangeList = append(ipRangeList, ipRange) + continue + } // if it's an ip turn it into a cidr if ip := net.ParseIP(cidr); ip != nil { switch { @@ -320,32 +335,21 @@ func process(wg *sync.WaitGroup, chancidr, outputchan chan string) { if options.Aggregate || options.Shuffle || hasSort || options.AggregateApprox || options.Count { _ = ranger.Add(cidr) allCidrs = append(allCidrs, pCidr) - } else if options.Slices > 0 { - subnets, err := mapcidr.SplitN(cidr, options.Slices) - if err != nil { - gologger.Fatal().Msgf("%s\n", err) - } - for _, subnet := range subnets { - outputchan <- subnet.String() - } - } else if options.HostCount > 0 { - subnets, err := mapcidr.SplitByNumber(cidr, options.HostCount) - if err != nil { - gologger.Fatal().Msgf("%s\n", err) - } - for _, subnet := range subnets { - outputchan <- subnet.String() - } } else { - var ipFlagList []string - ipFlagList = append(ipFlagList, prepareIPsFromCidrFlagList(options.MatchIP)...) - ipFlagList = append(ipFlagList, prepareIPsFromCidrFlagList(options.FilterIP)...) - ips, err := mapcidr.IPAddressesAsStream(cidr) - if err != nil { - gologger.Fatal().Msgf("%s\n", err) - } - for ip := range ips { - filterIPsFromFlagList(outputchan, ip, ipFlagList) + commonFunc(cidr, outputchan) + } + } + + for _, ipRange := range ipRangeList { + cidrs, err := mapcidr.GetCIDRFromIPRange(ipRange[0], ipRange[1]) + 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) } } } @@ -415,6 +419,42 @@ func process(wg *sync.WaitGroup, chancidr, outputchan chan string) { close(outputchan) } +/* +The purpose of the function is split into subnets or split by no. of host or CIDR expansion. +This gives us benefit of DRY and we can add new features here going forward. +*/ +func commonFunc(cidr string, outputchan chan string) { + if options.Slices > 0 { + subnets, err := mapcidr.SplitN(cidr, options.Slices) + if err != nil { + gologger.Fatal().Msgf("%s\n", err) + } + for _, subnet := range subnets { + outputchan <- subnet.String() + } + } else if options.HostCount > 0 { + subnets, err := mapcidr.SplitByNumber(cidr, options.HostCount) + if err != nil { + gologger.Fatal().Msgf("%s\n", err) + } + for _, subnet := range subnets { + outputchan <- subnet.String() + } + } else { + var ipFlagList []string + ipFlagList = append(ipFlagList, prepareIPsFromCidrFlagList(options.MatchIP)...) + ipFlagList = append(ipFlagList, prepareIPsFromCidrFlagList(options.FilterIP)...) + + ips, err := mapcidr.IPAddressesAsStream(cidr) + if err != nil { + gologger.Fatal().Msgf("%s\n", err) + } + for ip := range ips { + filterIPsFromFlagList(outputchan, ip, ipFlagList) + } + } +} + func output(wg *sync.WaitGroup, outputchan chan string) { defer wg.Done() diff --git a/cmd/mapcidr/main_test.go b/cmd/mapcidr/main_test.go new file mode 100644 index 0000000..74c9fd9 --- /dev/null +++ b/cmd/mapcidr/main_test.go @@ -0,0 +1,201 @@ +package main + +import ( + "sync" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestProcess(t *testing.T) { + tests := []struct { + name string + chancidr chan string + outputchan chan string + options Options + expectedOutput []string + }{ + { + name: "CIDRExpansionIPv4", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + FileCidr: []string{"10.40.0.0/30"}, + }, + expectedOutput: []string{"10.40.0.0", "10.40.0.1", "10.40.0.2", "10.40.0.3"}, + }, + { + name: "CIDRExpansionIPv6", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + FileCidr: []string{"2c0f:fec9::/126"}, + }, + expectedOutput: []string{"2c0f:fec9::", "2c0f:fec9::1", "2c0f:fec9::2", "2c0f:fec9::3"}, + }, + { + name: "CIDRAggregationIPv4", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + + FileCidr: []string{"10.40.0.0/30", "10.40.0.4/30", "10.40.0.8/30", "10.40.0.12/30"}, + Aggregate: true, + }, + expectedOutput: []string{"10.40.0.0/28"}, + }, + { + name: "CIDRSliceByCountIPv4", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + + FileCidr: []string{"10.40.0.0/24"}, + Slices: 2, + }, + expectedOutput: []string{"10.40.0.0/25", "10.40.0.128/25"}, + }, + { + name: "CIDRSliceByHostIPv4", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + + FileCidr: []string{"10.40.0.0/24"}, + HostCount: 128, + }, + expectedOutput: []string{"10.40.0.0/25", "10.40.0.128/25"}, + }, + { + name: "IPRangeExpansionIPv4", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + + FileCidr: []string{"10.40.0.0-10.40.0.5"}, + }, + expectedOutput: []string{"10.40.0.0", "10.40.0.1", "10.40.0.2", "10.40.0.3", "10.40.0.4", "10.40.0.5"}, + }, + { + name: "IPRangeExpansionIPv6", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + + FileCidr: []string{"2c0f:fec9::-2c0f:fec9::3"}, + }, + expectedOutput: []string{"2c0f:fec9::", "2c0f:fec9::1", "2c0f:fec9::2", "2c0f:fec9::3"}, + }, + { + name: "IPRangeAggregationIPv4", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + + FileCidr: []string{"10.40.0.1-10.40.0.255"}, + Aggregate: true, + }, + expectedOutput: []string{"10.40.0.64/26", "10.40.0.32/27", "10.40.0.16/28", "10.40.0.8/29", "10.40.0.4/30", "10.40.0.2/31", "10.40.0.1/32", "10.40.0.128/25"}, + }, + { + name: "IPRangeAggregationIPv6", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + + FileCidr: []string{"2c0f:fec9::-2c0f:fed7:ffff:ffff:ffff:ffff:ffff:ffff"}, + Aggregate: true, + }, + expectedOutput: []string{"2c0f:fecc::/30", "2c0f:feca::/31", "2c0f:fec9::/32", "2c0f:fed0::/29"}, + }, + { + name: "IPRangeliceByCountIPv4", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + + FileCidr: []string{"10.40.0.0-10.40.0.255"}, + Slices: 2, + }, + expectedOutput: []string{"10.40.0.0/25", "10.40.0.128/25"}, + }, + { + name: "IPRangeSliceByHostIPv4", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + + FileCidr: []string{"10.40.0.0-10.40.0.255"}, + HostCount: 128, + }, + expectedOutput: []string{"10.40.0.0/25", "10.40.0.128/25"}, + }, { + name: "CombinationOneIPRangeAggregate", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + FileCidr: []string{"166.8.0.0/16", "166.11.0.0/16", "166.9.0.0-166.10.255.255"}, + Aggregate: true, + }, + expectedOutput: []string{"166.8.0.0/14"}, + }, { + name: "CombinationMultipleIPRangeAggregate", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + FileCidr: []string{"173.0.0.0/18", "173.0.64.0-173.0.127.255", "173.0.128.0/18", "173.0.192.0-173.0.255.255"}, + Aggregate: true, + }, + expectedOutput: []string{"173.0.0.0/16"}, + }, + { + name: "CombinationOneIPRangeCount", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + FileCidr: []string{"166.8.0.0/16", "166.11.0.0/16", "166.9.0.0-166.10.255.255"}, + Count: true, + }, + expectedOutput: []string{"262144"}, + }, { + name: "MultipleIPRangeAggregate", + chancidr: make(chan string), + outputchan: make(chan string), + options: Options{ + FileCidr: []string{"166.8.0.0-166.8.0.5", "166.8.0.5-166.8.0.255"}, + Aggregate: true, + }, + expectedOutput: []string{"166.8.0.0/24"}, + }, + } + var wg sync.WaitGroup + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + options = &tt.options + + wg.Add(1) + go process(&wg, tt.chancidr, tt.outputchan) + + var outputlist []string + // get output list + wg.Add(1) + go func() { + defer wg.Done() + for output := range tt.outputchan { + outputlist = append(outputlist, output) + } + }() + + for _, item := range tt.options.FileCidr { + tt.chancidr <- item + } + close(tt.chancidr) + wg.Wait() + + // compare output + require.Equal(t, tt.expectedOutput, outputlist) + }) + + } +} diff --git a/ip.go b/ip.go index 8a9d243..73701a0 100644 --- a/ip.go +++ b/ip.go @@ -1042,3 +1042,19 @@ func overflowLastOctect(ip net.IP) (string, error) { } return fmt.Sprintf("%s.%s.%d", parts[0], parts[1], part2+part3), nil } + +/* +The intent here is to get the CIDR range from the IP range. +This function will return the sorted list of CIDR ranges. +*/ +func GetCIDRFromIPRange(firstIP, lastIP net.IP) ([]*net.IPNet, error) { + // check if range is valid or not + if bytes.Compare(firstIP, lastIP) > 0 { + return nil, fmt.Errorf("start IP:%s must be less than End IP:%s", firstIP, lastIP) + } + cidrs := rangeToCIDRs(firstIP, lastIP) + sort.Slice(cidrs, func(i, j int) bool { + return bytes.Compare(cidrs[i].IP, cidrs[j].IP) < 0 + }) + return cidrs, nil +} diff --git a/ip_test.go b/ip_test.go index 24cfd71..f8f78a9 100644 --- a/ip_test.go +++ b/ip_test.go @@ -44,3 +44,59 @@ func TestIpEncodings(t *testing.T) { res = AlterIP("127.0.1.0", []string{"11"}, 0, false) require.Equal(t, []string{"127.0.256"}, res) } + +func TestRangeToCIDRs(t *testing.T) { + tests := []struct { + name string + firstIP net.IP + lastIP net.IP + want []string + expectedError string + }{ + { + name: "IP4SingleCIDR", + firstIP: net.ParseIP("192.168.0.0"), + lastIP: net.ParseIP("192.168.0.255"), + want: []string{"192.168.0.0/24"}, + expectedError: "", + }, + { + name: "IP4MultipleCIDR", + firstIP: net.ParseIP("192.168.0.1"), + lastIP: net.ParseIP("192.168.0.255"), + want: []string{"192.168.0.1/32", "192.168.0.2/31", + "192.168.0.4/30", "192.168.0.8/29", + "192.168.0.16/28", "192.168.0.32/27", + "192.168.0.64/26", "192.168.0.128/25"}, + expectedError: "", + }, + { + name: "IP6RangeCIDR", + firstIP: net.ParseIP("2c0f:fec9::"), + lastIP: net.ParseIP("2c0f:fed7:ffff:ffff:ffff:ffff:ffff:ffff"), + want: []string{"2c0f:fec9::/32", "2c0f:feca::/31", "2c0f:fecc::/30", "2c0f:fed0::/29"}, + expectedError: "", + }, + { + name: "wrongIPRange", + firstIP: net.ParseIP("192.168.0.255"), + lastIP: net.ParseIP("192.168.0.0"), + want: []string{}, + expectedError: "start IP:192.168.0.255 must be less than End IP:192.168.0.0", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var cidrStringList []string + got, err := GetCIDRFromIPRange(tt.firstIP, tt.lastIP) + if err != nil { + require.Equal(t, tt.expectedError, err.Error()) + } else { + for _, item := range got { + cidrStringList = append(cidrStringList, item.String()) + } + require.Equal(t, tt.want, cidrStringList) + } + }) + } +} From 4a772ee0bae4114834cfecc7f80d9049b84b36d6 Mon Sep 17 00:00:00 2001 From: sandeep <8293321+ehsandeep@users.noreply.github.com> Date: Mon, 12 Sep 2022 11:42:13 +0530 Subject: [PATCH 10/12] go mod update --- go.mod | 14 +++++++------- go.sum | 22 +++++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index edb8560..25c342d 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,16 @@ module github.com/projectdiscovery/mapcidr -go 1.17 +go 1.18 require ( github.com/pkg/errors v0.9.1 - github.com/projectdiscovery/blackrock v0.0.0-20210903102120-5a9d2412d21d - github.com/projectdiscovery/fileutil v0.0.0-20220609150212-453ac591c36c + github.com/projectdiscovery/blackrock v0.0.0-20220628111055-35616c71b2dc + github.com/projectdiscovery/fileutil v0.0.0-20220705195237-01becc2a8963 github.com/projectdiscovery/goflags v0.0.9 github.com/projectdiscovery/gologger v1.1.4 github.com/projectdiscovery/ipranger v0.0.3 - github.com/projectdiscovery/sliceutil v0.0.0-20220617151003-15892688e1d6 - github.com/projectdiscovery/stringsutil v0.0.0-20220612082425-0037ce9f89f3 + github.com/projectdiscovery/sliceutil v0.0.0-20220625085859-c3a4ecb669f4 + github.com/projectdiscovery/stringsutil v0.0.1 github.com/stretchr/testify v1.8.0 ) @@ -23,7 +23,7 @@ require ( 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.18 // 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 github.com/pmezard/go-difflib v1.0.0 // indirect @@ -35,6 +35,6 @@ require ( github.com/yl2chen/cidranger v1.0.2 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.8.0 // indirect - golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 // indirect + golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index ca9af49..720ff1e 100644 --- a/go.sum +++ b/go.sum @@ -32,8 +32,9 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= 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 h1:6HcxvXDAi3ARt3slx6nTesbvorIc3QeTzBNRvWktHBo= github.com/microcosm-cc/bluemonday v1.0.18/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM= +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/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,12 +51,14 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE 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/blackrock v0.0.0-20210415162320-b38689ae3a2e/go.mod h1:/IsapnEYiWG+yEDPXp0e8NWj3npzB9Ccy9lXEUJwMZs= -github.com/projectdiscovery/blackrock v0.0.0-20210903102120-5a9d2412d21d h1:1Q94movG4VMVo+qf781ttXXt2bxBOIGMenmuCAJDLfE= 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= +github.com/projectdiscovery/blackrock v0.0.0-20220628111055-35616c71b2dc/go.mod h1:5tNGQP9kOfW+X5+40pZP8aqPYLHs45nJkFaSHLxdeH8= github.com/projectdiscovery/fileutil v0.0.0-20210928100737-cab279c5d4b5/go.mod h1:U+QCpQnX8o2N2w0VUGyAzjM3yBAe4BKedVElxiImsx0= github.com/projectdiscovery/fileutil v0.0.0-20220506114156-c4ab20801483/go.mod h1:wjS/oBWbzlayJ/aTK0KW0oOHGO03G8oEYzuN6stI8Ho= -github.com/projectdiscovery/fileutil v0.0.0-20220609150212-453ac591c36c h1:/+xJK8e/Gj/zAmudWh5l2SzGJB+CkwYnraelCkBe7Aw= 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/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.9 h1:bPsYIPE1LvdgYaM3XNX0YmS68e6huv22W22rKh5IscI= @@ -77,12 +80,14 @@ github.com/projectdiscovery/mapcidr v1.0.0/go.mod h1:5QkKrV6rNQQurCZI3nNedFsAOYp 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/sliceutil v0.0.0-20220617151003-15892688e1d6 h1:zZmLOwj2duDafEO9i1KqmHMW0SL9+Wwmco9sxhBCVwQ= 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 h1:EbP+rVR7NPsFKfwhzshmXP2GMjqBpaMZurJzQ5PYvbY= github.com/projectdiscovery/stringsutil v0.0.0-20220612082425-0037ce9f89f3/go.mod h1:mF5sh4jTghoGWwgUb9qWi5waTFklClDbtrqtJU93awc= +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= github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -93,6 +98,7 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/stretchr/testify v1.7.3/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= @@ -105,15 +111,17 @@ 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/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 h1:Yqz/iviulwKwAREEeUd3nbBFn0XuyJqkoft2IlrvOhc= golang.org/x/net v0.0.0-20220617184016-355a448f1bc9/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b h1:ZmngSVLe/wycRns9MKikG9OWIEjGcGAkacif7oYQaUY= +golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/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-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/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/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= From d7577a8a97b9164fc9e6357209e5510257bd91cc Mon Sep 17 00:00:00 2001 From: Shubham Rasal Date: Mon, 12 Sep 2022 18:12:37 +0530 Subject: [PATCH 11/12] Update goflags version (#101) * 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 Co-authored-by: Sandeep Singh Co-authored-by: Jaideep Khandelwal Co-authored-by: Siddharth Shashikar <60960197+shashikarsiddharth@users.noreply.github.com> --- go.mod | 4 ++-- go.sum | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 25c342d..72d398f 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( 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 - github.com/projectdiscovery/goflags v0.0.9 + github.com/projectdiscovery/goflags v0.0.10-0.20220912115102-d9ea875a0a6a github.com/projectdiscovery/gologger v1.1.4 github.com/projectdiscovery/ipranger v0.0.3 github.com/projectdiscovery/sliceutil v0.0.0-20220625085859-c3a4ecb669f4 @@ -35,6 +35,6 @@ require ( github.com/yl2chen/cidranger v1.0.2 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.8.0 // indirect - golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b // indirect + golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 720ff1e..1ce88de 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,8 @@ github.com/projectdiscovery/fileutil v0.0.0-20220705195237-01becc2a8963 h1:4o97N github.com/projectdiscovery/fileutil v0.0.0-20220705195237-01becc2a8963/go.mod h1:DaY7wmLPMleyHDCD/14YApPCDtrARY4J8Eny2ZGsG/g= 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.9 h1:bPsYIPE1LvdgYaM3XNX0YmS68e6huv22W22rKh5IscI= -github.com/projectdiscovery/goflags v0.0.9/go.mod h1:t/dEhv2VDOzayugXZCkbkX8n+pPeVmRD+WgQRSgReeI= +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/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= @@ -112,8 +112,9 @@ go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95a 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= -golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b h1:ZmngSVLe/wycRns9MKikG9OWIEjGcGAkacif7oYQaUY= 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/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= From 835671e945957a3e38c41269457a95e54ab38bad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 13 Sep 2022 03:42:06 +0530 Subject: [PATCH 12/12] chore(deps): bump golang from 1.19.0-alpine to 1.19.1-alpine (#102) Bumps golang from 1.19.0-alpine to 1.19.1-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 97a1a17..67ebb78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19.0-alpine AS build-env +FROM golang:1.19.1-alpine AS build-env RUN go install -v github.com/projectdiscovery/mapcidr/cmd/mapcidr@latest FROM alpine:latest