diff --git a/README.md b/README.md index 2680175..6f8ad28 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Usage: Flags: INPUT: - -a, -asn string[] target asn to lookup, example: -a AS5650 + -a, -asn string[] target asn to lookup, example: -a AS5650, -a 5650 -i, -ip string[] target ip to lookup, example: -i 100.19.12.21, -i 2a10:ad40:: -d, -domain string[] target domain to lookup, example: -d google.com, -d facebook.com -org string[] target organization to lookup, example: -org GOOGLE diff --git a/runner/options.go b/runner/options.go index 239004e..d13a899 100644 --- a/runner/options.go +++ b/runner/options.go @@ -4,7 +4,6 @@ import ( "errors" "io" "os" - "strings" asnmap "github.com/projectdiscovery/asnmap/libs" "github.com/projectdiscovery/goflags" @@ -77,8 +76,8 @@ func (options *Options) validateOptions() error { // validate asn input if options.Asn != nil { for _, asn := range options.Asn { - if !strings.HasPrefix(strings.ToUpper(asn), "AS") { - return errors.New("invalid ASN given. it should start with prefix 'AS', example : AS14421") + if t := asnmap.IdentifyInput(asn); t != asnmap.ASN && t != asnmap.ASNID { + return errors.New("invalid ASN given, example: AS14421 or 14421") } } } @@ -93,7 +92,7 @@ func ParseOptions() *Options { // Input flagSet.CreateGroup("input", "Input", - flagSet.StringSliceVarP(&options.Asn, "asn", "a", nil, "target asn to lookup, example: -a AS5650", goflags.FileNormalizedStringSliceOptions), + flagSet.StringSliceVarP(&options.Asn, "asn", "a", nil, "target asn to lookup, example: -a AS5650, -a 5650", goflags.FileNormalizedStringSliceOptions), flagSet.StringSliceVarP(&options.Ip, "ip", "i", nil, "target ip to lookup, example: -i 100.19.12.21, -i 2a10:ad40:: ", goflags.FileNormalizedStringSliceOptions), flagSet.StringSliceVarP(&options.Domain, "domain", "d", nil, "target domain to lookup, example: -d google.com, -d facebook.com", goflags.FileNormalizedStringSliceOptions), flagSet.StringSliceVar(&options.Org, "org", nil, "target organization to lookup, example: -org GOOGLE", goflags.StringSliceOptions), diff --git a/runner/options_test.go b/runner/options_test.go new file mode 100644 index 0000000..1f32025 --- /dev/null +++ b/runner/options_test.go @@ -0,0 +1,18 @@ +package runner + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestValidateASNInput(t *testing.T) { + for _, asn := range []string{"AS13335", "as13335", "13335"} { + options := &Options{Asn: []string{asn}} + require.NoError(t, options.validateOptions(), asn) + } + for _, asn := range []string{"ASX", "google", "AS"} { + options := &Options{Asn: []string{asn}} + require.Error(t, options.validateOptions(), asn) + } +}