Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix registering hostname with ip in DailerHistory #314

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastdialer/dialer_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (d *Dialer) dial(ctx context.Context, opts *dialOptions) (conn net.Conn, er
opts.ips = []string{ip}
opts.port = port
// also set hostname by parsing it from address
hostname, _, _ := net.SplitHostPort(opts.address)
hostname, _, _ = net.SplitHostPort(opts.address)
opts.hostname = hostname
}

Expand Down
23 changes: 23 additions & 0 deletions tests/fastdialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tests
import (
"context"
"crypto/tls"
"net"
"net/http"
"sync"
"testing"
Expand Down Expand Up @@ -128,6 +129,28 @@ func TestFastDialerDomainMultiIP(t *testing.T) {
require.NotNil(t, conn)
_ = conn.Close()
})

t.Run("Dial TCP Domain with port 80", func(t *testing.T) {
t.Parallel()
opts.WithDialerHistory = true
fdN, err := fastdialer.NewDialer(opts)
require.Nil(t, err)
defer fdN.Close()

var connN net.Conn
ctx := context.TODO()
target := "projectdiscovery.io"
connN, err = fdN.DialTLS(ctx, "tcp", target+":80")
require.NotNil(t, err)
require.Nil(t, connN)

connN, err = fdN.Dial(ctx, "tcp", target+":80")
require.Nil(t, err)
defer connN.Close()

require.NotNil(t, connN)
require.NotEmpty(t, fdN.GetDialedIP(target))
})
}

func TestFastDialerDomainsInvalid(t *testing.T) {
Expand Down
Loading