Skip to content

Commit 837448c

Browse files
authored
Merge pull request #35 from projectdiscovery/bugfix-json-output
corrected json output
2 parents 6cb9f38 + 36afb46 commit 837448c

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ require (
77
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
88
github.com/projectdiscovery/gologger v1.0.0
99
github.com/remeh/sizedwaitgroup v1.0.0
10-
golang.org/x/net v0.0.0-20200528225125-3c3fba18258b
10+
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
1111
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
1414
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
1515
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
1616
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
17-
golang.org/x/net v0.0.0-20200528225125-3c3fba18258b h1:IYiJPiJfzktmDAO1HQiwjMjwjlYKHAL7KzeD544RJPs=
18-
golang.org/x/net v0.0.0-20200528225125-3c3fba18258b/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
17+
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM=
18+
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
1919
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
2020
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
2121
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=

pkg/runner/enumerate.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package runner
22

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

103-
for port := range results {
104-
gologger.Silentf("%s:%d\n", host, port)
104+
if r.options.JSON {
105+
data := JSONResult{Host: host}
106+
for port := range results {
107+
data.Port = port
108+
b, err := json.Marshal(data)
109+
if err != nil {
110+
continue
111+
}
112+
gologger.Silentf("%s\n", string(b))
113+
}
114+
} else {
115+
for port := range results {
116+
gologger.Silentf("%s:%d\n", host, port)
117+
}
105118
}
106119

107120
// In case the user has given an output file, write all the found

pkg/runner/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func ParseOptions() *Options {
4343
flag.StringVar(&options.PortsFile, "ports-file", "", "File containing ports to enumerate for on hosts")
4444
flag.StringVar(&options.Output, "o", "", "File to write output to (optional)")
4545
flag.StringVar(&options.OutputDirectory, "oD", "", "Directory to write enumeration results to (optional)")
46-
flag.BoolVar(&options.JSON, "oJ", false, "Write output in JSON lines Format")
46+
flag.BoolVar(&options.JSON, "json", false, "Write output in JSON lines Format")
4747
flag.BoolVar(&options.Silent, "silent", false, "Show only host:ports in output")
4848
flag.IntVar(&options.Retries, "retries", 1, "Number of retries for the port scan probe")
4949
flag.IntVar(&options.Rate, "rate", 1000, "Rate of port scan probe requests")

0 commit comments

Comments
 (0)