Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ _testmain.go

vendor

reverse-scan
reverse-scan
bin/*
86 changes: 86 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
run:
concurrency: 4
issues-exit-code: 1
tests: true

output:
formats:
- format: colored-line-number
print-issued-lines: true
print-linter-name: true

linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
- asciicheck
- bodyclose
- dogsled
- durationcheck
- errorlint
- exhaustive
- exportloopref
- forcetypeassert
- gci
- gochecknoglobals
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- gofumpt
- goimports
- gomodguard
- goprintffuncname
- gosec
- importas
- makezero
- misspell
- nakedret
- nestif
- nilerr
- noctx
- nolintlint
- prealloc
- predeclared
- revive
- rowserrcheck
- sqlclosecheck
- thelper
- tparallel
- unconvert
- unparam
- wastedassign
- whitespace

linters-settings:
gocyclo:
min-complexity: 35

revive:
rules:
- name: exported
disabled: true

issues:
exclude-use-default: false
exclude-rules:
- text: "SA1029"
linters:
- staticcheck

# Exclude some linters from running on test files
- path: _test\.go
linters:
# bodyclose reports some false-positives when using a test request recorder
- bodyclose
# It's overkill to use `NewRequestWithContext` in tests
- noctx
- goerr113
# It's expected to have repeated text appearances in unit tests, and overkill to define constants for those
- goconst
24 changes: 19 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
FROM golang:1.12
ADD . /app
WORKDIR /app
RUN make install
ENTRYPOINT [ "/go/bin/reverse-scan" ]
FROM golang:1.22-alpine AS build

RUN apk add --no-cache bash git make build-base

WORKDIR /build

COPY go.mod go.sum ./

RUN go mod download

COPY . .

RUN make bin/reverse-scan

FROM alpine:3 AS runtime

COPY --from=build /build/bin/reverse-scan /usr/local/bin/reverse-scan

ENTRYPOINT [ "/usr/local/bin/reverse-scan" ]
38 changes: 30 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
GO111MODULE=on
GO ?= go
GOTEST = go test -v -bench\=.
WORKDIR ?= $(shell pwd)

.PHONY: install
install:
$(GO) install -ldflags="-s -w" -tags netgo
SHELL := /bin/bash

BUILD_FILES = $(shell go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}}\
{{end}}' ./...)

VERSION ?= $(shell git describe --tags 2>/dev/null || git rev-parse --short HEAD)
DATE_FMT = +%Y-%m-%d
ifdef SOURCE_DATE_EPOCH
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
else
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
endif

GO_LDFLAGS := -s -w
GO_LDFLAGS := -X go.pixelfactory.io/pkg/version.REVISION=$(VERSION) $(GO_LDFLAGS)
GO_LDFLAGS := -X go.pixelfactory.io/pkg/version.BUILDDATE=$(BUILD_DATE) $(GO_LDFLAGS)
bin/reverse-scan: $(BUILD_FILES)
@go build -trimpath -ldflags "$(GO_LDFLAGS)" -o "$@"

gofmt:
@diff -u <(echo -n) <(gofmt -d -s .)
.PHONY: gofmt

lint:
@golangci-lint run ./...
.PHONY: lint

vet:
@go vet ./...
.PHONY: vet
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
Perform reverse DNS lookups on huge network ranges

This utility uses the "Dispatcher/Workers" pattern discribed here :
- https://gobyexample.com/worker-pools
- https://nesv.github.io/golang/2014/02/25/worker-queues-in-go.html
- http://marcio.io/2015/07/handling-1-million-requests-per-minute-with-golang/

# Getting Started
- <https://gobyexample.com/worker-pools>
- <https://nesv.github.io/golang/2014/02/25/worker-queues-in-go.html>
- <http://marcio.io/2015/07/handling-1-million-requests-per-minute-with-golang/>

## Getting Started

Download the binary :

Expand Down
29 changes: 16 additions & 13 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,36 @@ import (
"github.com/spf13/cobra"
)

var rootCmd = cobra.Command{
Use: "reverse-scan",
Short: "Reverse Scan",
Run: run,
}

var version string

// NewRootCmd will setup and return the root command
func NewRootCmd(v string) *cobra.Command {
// Set Version and ProgramName
version = v
func NewRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "reverse-scan",
Short: "Reverse Scan",
Run: run,
}

rootCmd.PersistentFlags().StringP("start", "s", "", "ip range start")
rootCmd.PersistentFlags().StringP("end", "e", "", "ip range end")
rootCmd.PersistentFlags().StringP("output", "o", "", "csv output file")
rootCmd.PersistentFlags().IntP("workers", "w", 8, "number of workers")

return &rootCmd
versionCmd := NewVersionCmd()
rootCmd.AddCommand(versionCmd)

return rootCmd
}

func run(cmd *cobra.Command, args []string) {
c, err := config.LoadConfig(cmd)
if err != nil {
log.Fatal(err)
return
}

err = scanner.Start(c)
if err != nil {
log.Fatal(err)
}

scanner.Start(c)
os.Exit(0)
}
21 changes: 12 additions & 9 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import (
"fmt"

"github.com/spf13/cobra"
"go.pixelfactory.io/pkg/version"
)

func init() {
rootCmd.AddCommand(versionCmd)
}
// NewVersionCmd will setup and return the version command
func NewVersionCmd() *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "Print the version number and build date",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("version: %s\n", version.REVISION)
fmt.Printf("build-date: %s\n", version.BUILDDATE)
},
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s\n", version)
},
return versionCmd
}
38 changes: 30 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
module github.com/amine7536/reverse-scan

go 1.12
go 1.22

require (
github.com/gosuri/uilive v0.0.0-20170323041506-ac356e6e42cd // indirect
github.com/gosuri/uiprogress v0.0.0-20170224063937-d0567a9d84a1
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mattn/go-isatty v0.0.2 // indirect
github.com/spf13/cobra v0.0.0-20170624150100-4d647c8944eb
github.com/spf13/pflag v1.0.0 // indirect
golang.org/x/sys v0.0.0-20170627160855-90796e5a05ce // indirect
github.com/gosuri/uiprogress v0.0.1
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
go.pixelfactory.io/pkg/version v0.1.0
)

require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gosuri/uilive v0.0.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading