{"record":{"id":"83a918f0f3da7846","repo":"owasp-amass/amass","slug":"failed-to-establish-a-connection-with-the-whois-se","errorCode":null,"errorMessage":"failed to establish a connection with the WHOIS server: %v","messagePattern":"failed to establish a connection with the WHOIS server: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/plugins/whois/bgptools/plugin.go","lineNumber":141,"sourceCode":"\tIP            netip.Addr\n\tPrefix        netip.Prefix\n\tCC            string\n\tRegistry      string\n\tAllocatedDate time.Time\n\tASName        string\n}\n\nfunc (bt *bgpTools) whois(ctx context.Context, ipstr string) (*bgpToolsRecord, error) {\n\tdial := amassnet.NewDialContext(3 * time.Second)\n\taddr := net.JoinHostPort(bt.addr, strconv.Itoa(bt.port))\n\n\t_ = bt.rlimit.Wait(ctx)\n\tctx, cancel := context.WithTimeout(ctx, 10*time.Second)\n\tdefer cancel()\n\n\tconn, err := dial(ctx, \"tcp\", addr)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to establish a connection with the WHOIS server: %v\", err)\n\t}\n\tdefer func() { _ = conn.Close() }()\n\n\tn, err := io.WriteString(conn, fmt.Sprintf(\"begin\\n%s\\nend\", ipstr))\n\tif err != nil || n == 0 {\n\t\treturn nil, fmt.Errorf(\"failed to send the request to the WHOIS server: %v\", err)\n\t}\n\n\tdata, err := io.ReadAll(conn)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error reading the response from the WHOIS server: %v\", err)\n\t}\n\n\trecord := strings.Split(string(data), \"|\")\n\t// Ensure the record contains the necessary details (AutonomousSystem and Netblock)\n\tif len(record) < 7 {\n\t\treturn nil, errors.New(\"received insufficient data from the WHOIS server\")\n\t}","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/engine/plugins/whois/bgptools/plugin.go#L123-L159","documentation":"The bgptools WHOIS plugin wraps the underlying TCP dial error when it cannot establish a connection to its WHOIS service (host/port from plugin config, dialed with a 3s dialer inside a 10s overall timeout). It is a network-connectivity failure of the outbound TCP connection to the bgp.tools WHOIS endpoint, surfaced from the plugin's internal `whois` method.","triggerScenarios":"Calling the plugin's query path, which invokes whois(ctx, ipstr): the TCP dial to bt.addr:bt.port fails — the server is down, DNS for bt.addr fails, the network is unreachable, a firewall drops the connection, or the 10s context timeout expires before the dial completes.","commonSituations":"No outbound internet access or blocked port 43 in sandboxes/CI containers; the configured WHOIS server address is wrong or points to a host that no longer resolves; the bgp.tools service is temporarily unavailable; corporate proxies/firewalls that only allow HTTP(S).","solutions":["Verify outbound TCP connectivity to the configured WHOIS host/port (e.g. `nc -vz <host> <port>`) and fix network/firewall/proxy rules","Check the plugin's configured server address (bt.addr/bt.port) for typos or stale values","Confirm DNS resolution works in the environment; test with `dig`/`nslookup`","Retry later or switch to an alternate WHOIS data source plugin if bgp.tools is down","Check the wrapped cause (`%v` of the dial error) to distinguish DNS failure, timeout, and connection refused"],"exampleFix":"// before\naddr := net.JoinHostPort(\"whois.bgp.tools\", \"43\") // wrong host hardcoded/typo\n// after\naddr := net.JoinHostPort(bt.addr, strconv.Itoa(bt.port)) // validated config, port 43 reachable","handlingStrategy":"retry","validationCode":"// before querying\nfunc canReachWhois(host string, port int) bool {\n    conn, err := net.DialTimeout(\"tcp\", net.JoinHostPort(host, strconv.Itoa(port)), 3*time.Second)\n    if err != nil { return false }\n    _ = conn.Close()\n    return true\n}","typeGuard":null,"tryCatchPattern":"errgroup-style retry with backoff:\nvar rec *bgpToolsRecord\nfor attempt := 0; attempt < 3; attempt++ {\n    rec, err = plugin.Query(ctx, ip)\n    if err == nil { break }\n    if !isNetworkErr(err) { return err } // don't retry non-network failures\n    time.Sleep(time.Duration(1<<attempt) * time.Second)\n}","preventionTips":["Pre-flight check TCP reachability of the WHOIS host/port before batch queries","Validate the configured server address and port at plugin setup time","Run in an environment with outbound access to port 43 (adjust firewalls in CI/containers)","Treat this error as transient and retry with exponential backoff"],"tags":["network","tcp","whois","connection","timeout"],"backgroundTag":"connection-refused","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}