Skip to content

Commit

Permalink
Merge pull request #35 from projectdiscovery/bugfix-json-output
Browse files Browse the repository at this point in the history
corrected json output
  • Loading branch information
ehsandeep authored Jun 4, 2020
2 parents 6cb9f38 + 36afb46 commit 837448c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ require (
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/projectdiscovery/gologger v1.0.0
github.com/remeh/sizedwaitgroup v1.0.0
golang.org/x/net v0.0.0-20200528225125-3c3fba18258b
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200528225125-3c3fba18258b h1:IYiJPiJfzktmDAO1HQiwjMjwjlYKHAL7KzeD544RJPs=
golang.org/x/net v0.0.0-20200528225125-3c3fba18258b/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM=
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
Expand Down
17 changes: 15 additions & 2 deletions pkg/runner/enumerate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package runner

import (
"encoding/json"
"net"
"os"
"time"
Expand Down Expand Up @@ -100,8 +101,20 @@ func (r *Runner) EnumerateSingleHost(host string, ports map[int]struct{}, output
}
gologger.Infof("Found %d ports on host %s (%s)\n", len(results), host, hostIP)

for port := range results {
gologger.Silentf("%s:%d\n", host, port)
if r.options.JSON {
data := JSONResult{Host: host}
for port := range results {
data.Port = port
b, err := json.Marshal(data)
if err != nil {
continue
}
gologger.Silentf("%s\n", string(b))
}
} else {
for port := range results {
gologger.Silentf("%s:%d\n", host, port)
}
}

// In case the user has given an output file, write all the found
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func ParseOptions() *Options {
flag.StringVar(&options.PortsFile, "ports-file", "", "File containing ports to enumerate for on hosts")
flag.StringVar(&options.Output, "o", "", "File to write output to (optional)")
flag.StringVar(&options.OutputDirectory, "oD", "", "Directory to write enumeration results to (optional)")
flag.BoolVar(&options.JSON, "oJ", false, "Write output in JSON lines Format")
flag.BoolVar(&options.JSON, "json", false, "Write output in JSON lines Format")
flag.BoolVar(&options.Silent, "silent", false, "Show only host:ports in output")
flag.IntVar(&options.Retries, "retries", 1, "Number of retries for the port scan probe")
flag.IntVar(&options.Rate, "rate", 1000, "Rate of port scan probe requests")
Expand Down

0 comments on commit 837448c

Please sign in to comment.