Function resolve

  • Resolve a Host to an IP

    Parameters

    • host: string
    • prefer: "v4" | "v6" = 'v4'
    • mode: "dns" | "fetch" = 'fetch'

    Returns Promise<IPAddress | null>

    Example

    import { dns } from "@rjweb/utils"

    await dns.resolve('1.1.1.1') // <IPAddress v4 1.1.1.1>
    await dns.resolve('google.com', 'v4') // <IPAddress v4 142.250.185.78>
    await dns.resolve('google.com', 'v6') // <IPAddress v4 2a00:1450:400d:803::200e:>
    await dns.resolve('google.cdom', 'v6') // null

    Since

    1.8.0

    Supports

    nodejs, browser

    Default

    prefer = 'v4'
    mode = 'fetch'