Skip to content

k.net.DNS ​

DNS lookups, reverse resolution, and Whois

Execution ContextPrerequisitesTypical Use
KScript API, Page / View server scriptsOutbound DNS/Whois access; property name DNS is uppercaseHostname resolution, mail MX checks, reverse DNS, and Whois lookups

k.net.DNS provides host name resolution and email/domain record queries. The property name is DNS (case-sensitive).

Quick Start ​

js
k.api.get("resolve", () => {
  const ips = k.net.DNS.getIPs("kooboo.com")
  const mx = k.net.DNS.getMXs("kooboo.com")
  return {
    firstIp: ips && ips[0] ? ips[0].address : null,
    mxCount: mx ? mx.length : 0
  }
})

Quick Reference ​

Method / PropertyDescriptionReturns
getIPs([nsServer,] host)Resolve hostname to IP list, optionally via custom DNS serverKIPAddress[] | null
getMXs([nsServer,] host)Query MX mail exchange records, optionally via custom DNS serverstring[] | null
getNsServers(host)Retrieve authoritative NS servers for a domainstring[] | null
getReverseDNS(ip)Perform reverse DNS (PTR) lookup for an IPstring | null
whoisInfo(host)Retrieve raw Whois record text for a domainstring | null

getIPs() ​

Resolve a hostname to a list of IP records; pass a custom DNS server with the two-argument overload (note that nsServer comes before host in the 2-argument overload).

OverloadDescription
getIPs(host)Use system default DNS (returns IPv4 and IPv6 addresses)
getIPs(nsServer, host)Query records using the specified NS server (nsServer is the 1st argument; queries IPv4 A records only, not AAAA)
ParameterTypeRequiredDescription
nsServerstringNoDNS server to query (passed as the 1st argument in getIPs(nsServer, host))
hoststringYesHostname or domain to resolve

Returns: KIPAddress[] | null.

js
k.api.get("resolve", () => {
  const ips = k.net.DNS.getIPs("kooboo.com")
  return {
    count: ips ? ips.length : 0,
    first: ips && ips[0] ? ips[0].address : null
  }
})

KIPAddress ​

Field / MethodDescription
addressIP string
isIP4 / isIP6Address family
toIP4() / toIP6()Mapped IP string

getMXs() ​

Query MX records for a domain (note that nsServer comes before host in the 2-argument overload).

OverloadDescription
getMXs(host)Default resolution
getMXs(nsServer, host)Specify DNS server (nsServer is the 1st argument)
ParameterTypeRequiredDescription
nsServerstringNoDNS server to query (passed as the 1st argument in getMXs(nsServer, host))
hoststringYesDomain to query MX records for

Returns: string[] | null.

js
const records = k.net.DNS.getMXs("kooboo.com")

getNsServers() ​

Get the NS server list for a domain name.

ParameterTypeRequiredDescription
hoststringYesDomain to query NS records for

Returns: string[] | null. NS server list.

js
const ns = k.net.DNS.getNsServers("kooboo.com")

getReverseDNS() ​

Perform reverse DNS lookup on an IP address.

ParameterTypeRequiredDescription
ipstringYesIP address to reverse resolve

Returns: string | null. Resolved hostname.

js
const host = k.net.DNS.getReverseDNS("8.8.8.8")

whoisInfo() ​

Returns the raw Whois record text for a domain name.

ParameterTypeRequiredDescription
hoststringYesDomain to query Whois for

Returns: string | null. Raw Whois text.

js
const raw = k.net.DNS.whoisInfo("kooboo.com")

TypeScript Definitions ​

ts
interface KDNS {
  getIPs(host: string): KIPAddress[];
  getIPs(NSServer: string, host: string): KIPAddress[];
  getReverseDNS(IP: string): string;
  getMXs(nsServer: string, host: string): string[];
  getMXs(host: string): string[];
  getNsServers(host: string): string[];
  whoisInfo(host: string): string;
}

interface KIPAddress {
  address: string;
  isIP4: boolean;
  isIP6: boolean;
  toIP4(): string;
  toIP6(): string;
}
  • k.net.IP — IP geography (complementary to DNS resolution)