k.net.DNS
DNS lookups, reverse resolution, and Whois
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
| KScript API, Page / View server scripts | Outbound DNS/Whois access; property name DNS is uppercase | Hostname 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 / Property | Description | Returns |
|---|---|---|
getIPs([nsServer,] host) | Resolve hostname to IP list, optionally via custom DNS server | KIPAddress[] | null |
getMXs([nsServer,] host) | Query MX mail exchange records, optionally via custom DNS server | string[] | null |
getNsServers(host) | Retrieve authoritative NS servers for a domain | string[] | null |
getReverseDNS(ip) | Perform reverse DNS (PTR) lookup for an IP | string | null |
whoisInfo(host) | Retrieve raw Whois record text for a domain | string | 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).
| Overload | Description |
|---|---|
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) |
| Parameter | Type | Required | Description |
|---|---|---|---|
nsServer | string | No | DNS server to query (passed as the 1st argument in getIPs(nsServer, host)) |
host | string | Yes | Hostname 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 / Method | Description |
|---|---|
address | IP string |
isIP4 / isIP6 | Address family |
toIP4() / toIP6() | Mapped IP string |
getMXs()
Query MX records for a domain (note that nsServer comes before host in the 2-argument overload).
| Overload | Description |
|---|---|
getMXs(host) | Default resolution |
getMXs(nsServer, host) | Specify DNS server (nsServer is the 1st argument) |
| Parameter | Type | Required | Description |
|---|---|---|---|
nsServer | string | No | DNS server to query (passed as the 1st argument in getMXs(nsServer, host)) |
host | string | Yes | Domain 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.
| Parameter | Type | Required | Description |
|---|---|---|---|
host | string | Yes | Domain 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.
| Parameter | Type | Required | Description |
|---|---|---|---|
ip | string | Yes | IP 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.
| Parameter | Type | Required | Description |
|---|---|---|---|
host | string | Yes | Domain 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;
}Related Docs
- k.net.IP — IP geography (complementary to DNS resolution)