Skip to content

Commit

Permalink
fix module
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jul 3, 2024
1 parent b6c2ed9 commit c0d48bf
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
31 changes: 26 additions & 5 deletions cmd/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd

import (
"fmt"
"strconv"
"strings"

"github.com/godspeedcurry/godscan/common"
Expand All @@ -16,7 +17,7 @@ type PortOptions struct {
IpRange string
IpRangeFile string
PortRange string
TopPorts int
TopPorts string
useAllProbes bool
nullProbeOnly bool
scanSendTimeout int
Expand All @@ -43,7 +44,7 @@ func init() {
ipCmd.PersistentFlags().StringVarP(&portOptions.IpRangeFile, "host-file", "I", "", "your ip list file")

ipCmd.PersistentFlags().StringVarP(&portOptions.PortRange, "port", "p", strings.Join(common.DefaultPorts, ","), "your port list")
ipCmd.PersistentFlags().IntVarP(&portOptions.TopPorts, "top", "", 0, "top ports to scan, default is 500")
ipCmd.PersistentFlags().StringVarP(&portOptions.TopPorts, "top", "", "", "top ports to scan, default is empty")

ipCmd.PersistentFlags().IntVarP(&portOptions.scanSendTimeout, "scan-send-timeout", "s", 5, "Set connection send timeout in seconds")
ipCmd.PersistentFlags().IntVarP(&portOptions.scanReadTimeout, "scan-read-timeout", "r", 5, "Set connection read timeout in seconds")
Expand Down Expand Up @@ -90,12 +91,32 @@ func (o *PortOptions) run() {
utils.Info("Please provide ip range or ip range file")
return
}
if portOptions.TopPorts != 0 {
if portOptions.TopPorts > 20000 {
if portOptions.TopPorts != "" {
if strings.Contains(portOptions.TopPorts, "-") {
TopRangeBounds := strings.Split(portOptions.TopPorts, "-")
if len(TopRangeBounds) != 2 {
return
}

startPort, err := strconv.Atoi(strings.TrimSpace(TopRangeBounds[0]))
if err != nil {
return
}

endPort, err := strconv.Atoi(strings.TrimSpace(TopRangeBounds[1]))
if err != nil {
return
}
if startPort > endPort || endPort > 20000 {
utils.Info("We do not have more than top 20000 ports, please choose a smaller number, or just scan all ports use `-p 0-65535`")
return
}
utils.PortScan(portOptions.IpRange, strings.Join(strings.Split(common.AllPorts, ",")[startPort:endPort], ","))
} else if startPort, err := strconv.Atoi(portOptions.TopPorts); err != nil || startPort > 20000 {
utils.Info("We do not have more than top 20000 ports, please choose a smaller number, or just scan all ports use `-p 0-65535`")
return
} else {
utils.PortScan(portOptions.IpRange, strings.Join(strings.Split(common.AllPorts, ",")[0:portOptions.TopPorts], ","))
utils.PortScan(portOptions.IpRange, strings.Join(strings.Split(common.AllPorts, ",")[0:startPort], ","))
}

} else {
Expand Down
7 changes: 6 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"
"strings"

"github.com/godspeedcurry/godscan/utils"
"github.com/fatih/color"
"github.com/google/go-github/v57/github"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -125,6 +125,11 @@ func Execute() {
viper.BindPFlag("proxy", rootCmd.PersistentFlags().Lookup("proxy"))
viper.SetDefault("proxy", SetProxyFromEnv())

if viper.GetString("proxy") != "" {
utils.Info("Proxy is %s", viper.GetString("proxy"))
} else {
utils.Info("Proxy is null")
}
viper.BindPFlag("private-ip", rootCmd.PersistentFlags().Lookup("private-ip"))
viper.SetDefault("private-ip", false)

Expand Down
6 changes: 1 addition & 5 deletions cmd/spider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ func (o *SpiderOptions) validateOptions() error {
func (o *SpiderOptions) run() {
utils.InitHttp()
targetUrlList := GetTargetList()
if viper.GetString("proxy") != "" {
utils.Info("Total: %d url(s) Proxy: %s", len(targetUrlList), viper.GetString("proxy"))
} else {
utils.Info("Total: %d url(s) Proxy: null", len(targetUrlList))
}
utils.Info("Total: %d url(s)", len(targetUrlList))

var wg sync.WaitGroup
for _, line := range targetUrlList {
Expand Down
2 changes: 1 addition & 1 deletion common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var WebPorts = []string{
"9443", "9998-9999",
}

//go:embed ports_20000.txt
//go:embed ports_20000
var customProbes string

var AllPorts = customProbes
Expand Down
1 change: 1 addition & 0 deletions common/ports_20000

Large diffs are not rendered by default.

0 comments on commit c0d48bf

Please sign in to comment.