From 7cfcff31be22013d458eb18fccb54ff73ebe013a Mon Sep 17 00:00:00 2001 From: majiayu000 <1835304752@qq.com> Date: Fri, 2 Jan 2026 11:59:10 +0800 Subject: [PATCH] fix: probe-all-ips now works correctly when URL contains port Use URL.Hostname() instead of URL.Host to extract the hostname for DNS resolution. This ensures the port number is not included in the DNS query when probing all IPs for a URL like http://example.com:8080. Fixes #2346 Signed-off-by: majiayu000 <1835304752@qq.com> --- runner/runner.go | 2 +- runner/runner_test.go | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/runner/runner.go b/runner/runner.go index 2bf4dd44..b708f6a4 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -1562,7 +1562,7 @@ func (r *Runner) targets(hp *httpx.HTTPX, target string) chan httpx.Target { results <- httpx.Target{Host: target} return } - ips, _, _, err := getDNSData(hp, URL.Host) + ips, _, _, err := getDNSData(hp, URL.Hostname()) if err != nil || len(ips) == 0 { results <- httpx.Target{Host: target} return diff --git a/runner/runner_test.go b/runner/runner_test.go index 850566b8..a6f94826 100644 --- a/runner/runner_test.go +++ b/runner/runner_test.go @@ -67,6 +67,36 @@ func TestRunner_probeall_targets(t *testing.T) { require.ElementsMatch(t, expected, got, "could not expected output") } +func TestRunner_probeall_targets_with_port(t *testing.T) { + options := &Options{ + ProbeAllIPS: true, + } + r, err := New(options) + require.Nil(t, err, "could not create httpx runner") + + inputWithPort := "http://one.one.one.one:8080" + inputWithoutPort := "one.one.one.one" + + gotWithPort := []httpx.Target{} + for target := range r.targets(r.hp, inputWithPort) { + gotWithPort = append(gotWithPort, target) + } + + gotWithoutPort := []httpx.Target{} + for target := range r.targets(r.hp, inputWithoutPort) { + gotWithoutPort = append(gotWithoutPort, target) + } + + require.True(t, len(gotWithPort) > 0, "probe-all-ips with port should return at least one target") + require.True(t, len(gotWithoutPort) > 0, "probe-all-ips without port should return at least one target") + require.Equal(t, len(gotWithPort), len(gotWithoutPort), "probe-all-ips should return same number of IPs with or without port") + + for _, target := range gotWithPort { + require.Equal(t, inputWithPort, target.Host, "Host should be preserved with port") + require.NotEmpty(t, target.CustomIP, "CustomIP should be populated") + } +} + func TestRunner_cidr_targets(t *testing.T) { options := &Options{} r, err := New(options) @@ -227,10 +257,10 @@ func TestCreateNetworkpolicyInstance_AllowDenyFlags(t *testing.T) { runner := &Runner{} tests := []struct { - name string - allow []string - deny []string - testCases []struct { + name string + allow []string + deny []string + testCases []struct { ip string expected bool reason string