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>
This commit is contained in:
majiayu000
2026-01-02 11:59:10 +08:00
parent 7f9403e2ee
commit 7cfcff31be
2 changed files with 35 additions and 5 deletions
+1 -1
View File
@@ -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
+34 -4
View File
@@ -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