Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsandeep committed Feb 26, 2024
2 parents 496108b + a41995a commit d8e6f97
Show file tree
Hide file tree
Showing 20 changed files with 561 additions and 356 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ jobs:
working-directory: examples/

- name: Run test
run: go test ./...
run: go test ./...
env:
PDCP_API_KEY: "${{ secrets.PDCP_API_KEY }}"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.dylib
*.idea
.vscode
.devcontainer

# Test binary, built with `go test -c`
*.test
Expand All @@ -16,3 +17,5 @@
# Dependency directories (remove the comment below to include it)
# vendor/
dist/
/asnmap
/cmd/asnmap/asnmap
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ GOCMD=go
GOBUILD=$(GOCMD) build
GOMOD=$(GOCMD) mod
GOTEST=$(GOCMD) test
GOCLEAN=$(GOCMD) clean
GOFLAGS := -v
# This should be disabled if the binary uses pprof
LDFLAGS := -s -w

ifneq ($(shell go env GOOS),darwin)
LDFLAGS := -extldflags "-static"
endif


.PHONY: cli test tidy

cli:
$(GOBUILD) -v -ldflags="-extldflags=-static" -o "asnmap" ./cmd/asnmap/
cli, build:
$(GOBUILD) $(GOFLAGS) -ldflags '$(LDFLAGS)' -o "asnmap" ./cmd/asnmap/
test:
$(GOCLEAN) -testcache
$(GOTEST) -v ./...
Expand Down
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

## Installation

asnmap requires **Go 1.18** to install successfully. To install, just run the below command or download pre-compiled binary from [release page](https://github.com/projectdiscovery/asnmap/releases).
asnmap requires **Go 1.21** to install successfully. To install, just run the below command or download pre-compiled binary from [release page](https://github.com/projectdiscovery/asnmap/releases).

```console
go install github.com/projectdiscovery/asnmap/cmd/asnmap@latest
Expand Down Expand Up @@ -85,9 +85,36 @@ OUTPUT:
-version show version of the project
```

## Running asnmap
## Configuring ASNMap CLI

ASNMap CLI is built on top of the ASNMap API that requires API Token from [ProjectDiscovery Cloud Platform](https://cloud.projectdiscovery.io/?ref=api_key) that can be configured using environment variable or using interactive `-auth` option as shown below.

### Using environment variable

```console
export PDCP_API_KEY=*************
```

### Using auth option

```console
asnmap -auth


### Input for asnmap
___ _____ __
/ _ | / __/ |/ /_ _ ___ ____
/ __ |_\ \/ / ' \/ _ / _ \
/_/ |_/___/_/|_/_/_/_/\_,_/ .__/
/_/

projectdiscovery.io

[INF] Get your free api key by signing up at https://cloud.projectdiscovery.io
[*] Enter PDCP API Key (exit to abort): *************
[INF] Successfully logged in as (@user)
```

## Running asnmap

**asnmap** support multiple inputs including **ASN**, **IP**, **DNS** and **ORG** name to query ASN/CIDR information.

Expand Down
12 changes: 12 additions & 0 deletions cmd/asnmap/asnmap.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package main

import (
"errors"
"os"
"os/signal"

asnmap "github.com/projectdiscovery/asnmap/libs"
"github.com/projectdiscovery/asnmap/runner"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/utils/auth/pdcp"
)

func main() {
Expand Down Expand Up @@ -34,6 +37,15 @@ func main() {
}()

if err := asnmapRunner.Run(); err != nil {
if errors.Is(err, asnmap.ErrUnAuthorized) {
gologger.Info().Msgf("Try again after authenticating with PDCP\n\n")
// trigger auth callback
pdcp.CheckNValidateCredentials("asnmap")
// run again
if err := asnmapRunner.Run(); err != nil {
gologger.Fatal().Msgf("%s\n", err)
}
}
gologger.Fatal().Msgf("%s\n", err)
}
}
14 changes: 10 additions & 4 deletions examples/simple.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"fmt"
"encoding/json"
"log"

asnmap "github.com/projectdiscovery/asnmap/libs"
Expand Down Expand Up @@ -37,15 +37,21 @@ func main() {
}

func handleInput(client *asnmap.Client, item string) {
results, err := client.GetData(item)
responses, err := client.GetData(item)
if err != nil {
log.Fatal(err)
}
output, err := asnmap.GetFormattedDataInJson(results)
results, err := asnmap.MapToResults(responses)
if err != nil {
log.Fatal(err)
}

output, err := json.Marshal(results)
if err != nil {
log.Fatal(err)
}

if len(output) > 0 {
log.Println(fmt.Sprintf("%s: %s", item, string(output)))
log.Printf("%s: %s", item, string(output))
}
}
55 changes: 41 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module github.com/projectdiscovery/asnmap
go 1.21

require (
github.com/projectdiscovery/goflags v0.1.26
github.com/projectdiscovery/gologger v1.1.11
github.com/projectdiscovery/hmap v0.0.24
github.com/projectdiscovery/mapcidr v1.1.14
github.com/projectdiscovery/retryabledns v1.0.41
github.com/projectdiscovery/goflags v0.1.41
github.com/projectdiscovery/gologger v1.1.12
github.com/projectdiscovery/hmap v0.0.40
github.com/projectdiscovery/mapcidr v1.1.16
github.com/projectdiscovery/retryabledns v1.0.57
github.com/stretchr/testify v1.8.4
golang.org/x/net v0.17.0
)
Expand All @@ -27,46 +27,64 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/projectdiscovery/blackrock v0.0.1 // indirect
github.com/projectdiscovery/utils v0.0.62
github.com/projectdiscovery/utils v0.0.81
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/tools v0.13.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
aead.dev/minisign v0.2.0 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Mzack9999/gcache v0.0.0-20230410081825-519e28eab057 // 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/alecthomas/chroma v0.10.0 // indirect
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/glamour v0.6.0 // indirect
github.com/cheggaaa/pb/v3 v3.1.4 // indirect
github.com/denisbrodbeck/machineid v1.0.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/dlclark/regexp2 v1.8.1 // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gaukas/godicttls v0.0.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/golang/protobuf v1.5.3 // 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/klauspost/compress v1.16.7 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mholt/archiver v3.1.1+incompatible // indirect
github.com/mholt/archiver/v3 v3.5.1 // indirect
github.com/minio/selfupdate v0.6.1-0.20230907112617-f11e74f84ca7 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.1 // indirect
github.com/nwaples/rardecode v1.1.3 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/gomega v1.27.6 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pierrec/lz4/v4 v4.1.2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/projectdiscovery/fastdialer v0.0.59 // indirect
github.com/projectdiscovery/machineid v0.0.0-20240226150047-2e2c51e35983 // indirect
github.com/projectdiscovery/networkpolicy v0.0.7 // indirect
github.com/projectdiscovery/retryablehttp-go v1.0.48 // indirect
github.com/quic-go/quic-go v0.37.7 // indirect
github.com/refraction-networking/utls v1.5.4 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/shirou/gopsutil/v3 v3.23.7 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/tidwall/buntdb v1.3.0 // indirect
Expand All @@ -76,16 +94,25 @@ require (
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/rtred v0.1.2 // indirect
github.com/tidwall/tinyqueue v0.1.1 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6 // indirect
github.com/weppos/publicsuffix-go v0.30.1-0.20230422193905-8fecedd899db // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/yl2chen/cidranger v1.0.2 // indirect
github.com/yuin/goldmark v1.5.4 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
github.com/zmap/rc2 v0.0.0-20190804163417-abaa70531248 // indirect
github.com/zmap/zcrypto v0.0.0-20230422215203-9a665e1e9968 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
)
Loading

0 comments on commit d8e6f97

Please sign in to comment.