Skip to content

Commit 41c3759

Browse files
committed
adding output ip
1 parent 2ad12db commit 41c3759

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

pkg/runner/output.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010

1111
// JSONResult contains the result for a host in JSON format
1212
type JSONResult struct {
13-
Host string `json:"host"`
13+
Host string `json:"host,omitempty"`
14+
Ip string `json:"ip,omitempty"`
1415
Port int `json:"port"`
1516
}
1617

@@ -36,11 +37,14 @@ func WriteHostOutput(host string, ports map[int]struct{}, writer io.Writer) erro
3637
}
3738

3839
// WriteJSONOutput writes the output list of subdomain in JSON to an io.Writer
39-
func WriteJSONOutput(host string, ports map[int]struct{}, writer io.Writer) error {
40+
func WriteJSONOutput(host, ip string, ports map[int]struct{}, writer io.Writer) error {
4041
encoder := json.NewEncoder(writer)
4142

4243
data := JSONResult{}
43-
data.Host = host
44+
if host != ip {
45+
data.Host = host
46+
}
47+
data.Ip = ip
4448

4549
for port := range ports {
4650
data.Port = port

pkg/runner/runner.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ func (r *Runner) handleOutput() {
235235

236236
// console output
237237
if r.options.JSON {
238-
data := JSONResult{Host: host}
238+
data := JSONResult{Ip: hostIp}
239+
if host != hostIp {
240+
data.Host = host
241+
}
239242
for port := range ports {
240243
data.Port = port
241244
b, err := json.Marshal(data)
@@ -253,7 +256,7 @@ func (r *Runner) handleOutput() {
253256
// file output
254257
if file != nil {
255258
if r.options.JSON {
256-
err = WriteJSONOutput(host, ports, file)
259+
err = WriteJSONOutput(host, hostIp, ports, file)
257260
} else {
258261
err = WriteHostOutput(host, ports, file)
259262
}

pkg/runner/targets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (r *Runner) addOrExpand(target string) error {
8383
}
8484

8585
// If the user has specified ping probes, perform ping on addresses
86-
if r.options.Ping && len(initialHosts) > 1 {
86+
if isRoot() && r.options.Ping && len(initialHosts) > 1 {
8787
// Scan the hosts found for ping probes
8888
pingResults, err := scan.PingHosts(initialHosts)
8989
if err != nil {

0 commit comments

Comments
 (0)