Skip to content

Commit

Permalink
Merge pull request #167 from projectdiscovery/dev
Browse files Browse the repository at this point in the history
mapcidr v1.1.1
  • Loading branch information
ehsandeep authored Mar 18, 2023
2 parents 43c0610 + a56c587 commit 72a8d97
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 432 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: 🔨 Build Test
on:
pull_request:
paths:
- '**.go'
- '**.mod'
workflow_dispatch:


Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ name: 🚨 CodeQL Analysis
on:
workflow_dispatch:
pull_request:
branches:
- dev
paths:
- '**.go'
- '**.mod'

jobs:
analyze:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/dockerhub-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
- name: Get Github tag
id: meta
run: |
echo "::set-output name=tag::$(curl --silent "https://api.github.com/repos/projectdiscovery/mapcidr/releases/latest" | jq -r .tag_name)"
curl --silent "https://api.github.com/repos/projectdiscovery/mapcidr/releases/latest" | jq -r .tag_name | xargs -I {} echo TAG={} >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

Expand All @@ -36,4 +37,4 @@ jobs:
context: .
platforms: linux/amd64,linux/arm64,linux/arm
push: true
tags: projectdiscovery/mapcidr:latest,projectdiscovery/mapcidr:${{ steps.meta.outputs.tag }}
tags: projectdiscovery/mapcidr:latest,projectdiscovery/mapcidr:${{ steps.meta.outputs.TAG }}
3 changes: 3 additions & 0 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: 🙏🏻 Lint Test
on:
pull_request:
paths:
- '**.go'
- '**.mod'
workflow_dispatch:

jobs:
Expand Down
19 changes: 14 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
FROM golang:1.20.0-alpine AS build-env
RUN go install -v github.com/projectdiscovery/mapcidr/cmd/mapcidr@latest
# Base
FROM golang:1.20.1-alpine AS builder
RUN apk add --no-cache build-base
WORKDIR /app
COPY . /app
RUN go mod download
RUN go build ./cmd/mapcidr

FROM alpine:latest
COPY --from=build-env /go/bin/mapcidr /usr/local/bin/mapcidr
ENTRYPOINT ["mapcidr"]
# Release
FROM alpine:3.17.2
RUN apk -U upgrade --no-cache \
&& apk add --no-cache bind-tools ca-certificates
COPY --from=builder /app/mapcidr /usr/local/bin/

ENTRYPOINT ["mapcidr"]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ MISCELLANEOUS:
-si, -shuffle-ip Shuffle Input IPs in random order
-sp, -shuffle-port string Shuffle Input IP:Port in random order

UPDATE:
-up, -update update mapcidr to latest version
-duc, -disable-update-check disable automatic mapcidr update check

OUTPUT:
-verbose Verbose mode
-o, -output string File to write output to
Expand Down
34 changes: 29 additions & 5 deletions cmd/mapcidr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
asn "github.com/projectdiscovery/mapcidr/asn"
fileutil "github.com/projectdiscovery/utils/file"
sliceutil "github.com/projectdiscovery/utils/slice"
updateutils "github.com/projectdiscovery/utils/update"
)

// Options contains cli options
Expand Down Expand Up @@ -49,26 +50,32 @@ type Options struct {
IPFormats goflags.StringSlice
ZeroPadNumberOfZeroes int
ZeroPadPermute bool
DisableUpdateCheck bool
}

const banner = `
____________ ___
__ _ ___ ____ / ___/ _/ _ \/ _ \
/ ' \/ _ '/ _ \/ /___/ // // / , _/
/_/_/_/\_,_/ .__/\___/___/____/_/|_| v1.1.0
/_/_/_/\_,_/ .__/\___/___/____/_/|_|
/_/
`

// Version is the current version of mapcidr
const Version = `v1.1.0`
const version = `v1.1.1`

// showBanner is used to show the banner to the user
func showBanner() {
gologger.Print().Msgf("%s\n", banner)
gologger.Print().Msgf("\t\tprojectdiscovery.io\n\n")
}

gologger.Print().Msgf("Use with caution. You are responsible for your actions\n")
gologger.Print().Msgf("Developers assume no liability and are not responsible for any misuse or damage.\n")
// GetUpdateCallback returns a callback function that updates mapcidr
func GetUpdateCallback() func() {
return func() {
showBanner()
updateutils.GetUpdateToolCallback("mapcidr", version)()
}
}

// ParseOptions parses the command line options for application
Expand Down Expand Up @@ -114,6 +121,12 @@ func ParseOptions() *Options {
flagSet.StringVarP(&options.ShufflePorts, "shuffle-port", "sp", "", "Shuffle Input IP:Port in random order"),
)

//Update
flagSet.CreateGroup("update", "Update",
flagSet.CallbackVarP(GetUpdateCallback(), "update", "up", "update mapcidr to latest version"),
flagSet.BoolVarP(&options.DisableUpdateCheck, "disable-update-check", "duc", false, "disable automatic mapcidr update check"),
)

// Output
flagSet.CreateGroup("output", "Output",
flagSet.BoolVar(&options.Verbose, "verbose", false, "Verbose mode"),
Expand All @@ -132,10 +145,21 @@ func ParseOptions() *Options {
showBanner()

if options.Version {
gologger.Info().Msgf("Current Version: %s\n", Version)
gologger.Info().Msgf("Current Version: %s\n", version)
os.Exit(0)
}

if !options.DisableUpdateCheck {
latestVersion, err := updateutils.GetVersionCheckCallback("mapcidr")()
if err != nil {
if options.Verbose {
gologger.Error().Msgf("mapcidr version check failed: %v", err.Error())
}
} else {
gologger.Info().Msgf("Current mapcidr version %v %v", version, updateutils.GetVersionDescription(version, latestVersion))
}
}

// enable shuffling if ports are specified
if len(options.ShufflePorts) > 0 {
options.Shuffle = true
Expand Down
86 changes: 47 additions & 39 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,64 @@ go 1.18
require (
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/pkg/errors v0.9.1
github.com/projectdiscovery/asnmap v1.0.0
github.com/projectdiscovery/asnmap v1.0.2
github.com/projectdiscovery/blackrock v0.0.0-20221025011524-9e4efe804fb4
github.com/projectdiscovery/goflags v0.1.6
github.com/projectdiscovery/gologger v1.1.7
github.com/projectdiscovery/ipranger v0.0.4
github.com/projectdiscovery/utils v0.0.4-0.20221214110533-9f95ee986a54
github.com/stretchr/testify v1.8.1
golang.org/x/exp v0.0.0-20221230185412-738e83a70c30
github.com/projectdiscovery/goflags v0.1.8
github.com/projectdiscovery/gologger v1.1.8
github.com/projectdiscovery/ipranger v0.0.5
github.com/projectdiscovery/utils v0.0.16
github.com/stretchr/testify v1.8.2
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0
)

require (
github.com/DataDog/zstd v1.5.2 // indirect
aead.dev/minisign v0.2.0 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Mzack9999/go-http-digest-auth-client v0.6.1-0.20220414142836-eb8883508809 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/akrylysov/pogreb v0.10.1 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/charmbracelet/glamour v0.6.0 // indirect
github.com/cheggaaa/pb/v3 v3.1.2 // indirect
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 // indirect
github.com/cockroachdb/errors v1.9.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect
github.com/cockroachdb/pebble v0.0.0-20221229212011-811a8c0e741b // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.8.1 // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/getsentry/sentry-go v0.16.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-github/v30 v30.1.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.13 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mholt/archiver v3.1.1+incompatible // indirect
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/microcosm-cc/bluemonday v1.0.23 // indirect
github.com/miekg/dns v1.1.52 // indirect
github.com/minio/selfupdate v0.6.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.1 // indirect
github.com/nwaples/rardecode v1.1.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pierrec/lz4 v2.6.0+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/projectdiscovery/hmap v0.0.6 // indirect
github.com/projectdiscovery/hmap v0.0.10 // indirect
github.com/projectdiscovery/iputil v0.0.2 // indirect
github.com/projectdiscovery/networkpolicy v0.0.2-0.20221025011504-22b13ce54fff // indirect
github.com/projectdiscovery/retryabledns v1.0.20 // indirect
github.com/projectdiscovery/retryablehttp-go v1.0.8 // indirect
github.com/projectdiscovery/retryabledns v1.0.21 // indirect
github.com/projectdiscovery/retryablehttp-go v1.0.10 // indirect
github.com/projectdiscovery/stringsutil v0.0.2 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/tidwall/btree v1.4.3 // indirect
github.com/tidwall/buntdb v1.2.10 // indirect
Expand All @@ -69,17 +72,22 @@ require (
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/rtred v0.1.2 // indirect
github.com/tidwall/tinyqueue v0.1.1 // indirect
github.com/ulikunitz/xz v0.5.7 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/yl2chen/cidranger v1.0.2 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
github.com/yuin/goldmark v1.5.4 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/tools v0.2.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 72a8d97

Please sign in to comment.