net/dns
Finding the address of a name and asking for any kind of DNS record.
import net.dns
DNS turns names such as salamlang.ir into IP addresses. Lookup is the simplest way and does what a browser does. The Lookup... functions ask the DNS server for one particular kind of record and are what you want for building network tools or checking the configuration of a domain.
Types
Question
struct Question| Name | Type | Description |
|---|---|---|
name | str = "" | The domain name. |
qtype | int = 0 | The record type. |
qclass | int = 0 | The class. |
import net.dns
import compress
func main:
query := dns.EncodeQuery("salamlang.ir", dns.TypeA, 42)
println compress.BufLen(query), compress.BufToBase64(query)
m := dns.Decode(query.data, query.len)
println m.id, m.qr, m.rd, m.opcode, m.rcode, m.questions.items.len()
q := m.questions.items[0]
println q.name, q.qtype == dns.TypeA, q.qclass == dns.ClassIN
println m.answers.items.len(), m.authorities.items.len(), m.extras.items.len(), m.aa, m.tc, m.ra
println dns.TypeNS, dns.TypeCNAME, dns.TypeSOA, dns.TypePTR, dns.TypeMX, dns.TypeTXT, dns.TypeAAAA
println dns.Lookup("localhost")
println dns.DefaultServers().len() > 0
endQuestions
struct Questions| Name | Type | Description |
|---|---|---|
items | Vector | The questions. |
The example for this item is shown with the ones above: net-dns-Message.salam
Record
struct Record| Name | Type | Description |
|---|---|---|
name | str = "" | The domain name. |
rtype | int = 0 | The record type. |
rclass | int = 0 | The class. |
ttl | int = 0 | How many seconds the answer may be kept. |
priority | int = 0 | The priority of an MX record; a smaller number means a higher priority. |
data | str = "" | The record data as text: an address, a name or some text. |
import net.dns
func main:
println dns.LookupA("salamlang.ir")
println dns.LookupAAAA("salamlang.ir")
println dns.LookupCNAME("www.github.com")
mx := dns.LookupMX("gmail.com")
each m in mx.items:
println m.priority, m.data, m.ttl, m.rtype, m.rclass, m.name
end
println dns.LookupTXT("salamlang.ir")
println dns.LookupPTR("8.8.8.8")
answer := dns.QueryServer("1.1.1.1", "salamlang.ir", dns.TypeA, 2000)
println answer.answers.items.len()
endRecords
struct Records| Name | Type | Description |
|---|---|---|
items | Vector | The records. |
The example for this item is shown with the ones above: net-dns-Lookup.salam
Message
struct Message| Name | Type | Description |
|---|---|---|
id | int = 0 | The id that ties an answer to its question. |
qr | bool = false | The message is an answer. |
opcode | int = 0 | The kind of operation; zero is an ordinary question. |
aa | bool = false | The answer comes from the authoritative server. |
tc | bool = false | The answer was truncated. |
rd | bool = false | A recursive lookup was asked for. |
ra | bool = false | The server supports recursive lookups. |
rcode | int = 0 | The result code; zero means no error, 3 means the name does not exist. |
questions | Questions | The questions. |
answers | Records | The answers. |
authorities | Records | The authority records. |
extras | Records | The additional records. |
The example for this item is shown with the ones above: net-dns-Message.salam
Constants and variables
TypeA
const TypeA: i32 = 1The example for this item is shown with the ones above: net-dns-Message.salam
TypeNS
const TypeNS: i32 = 2The example for this item is shown with the ones above: net-dns-Message.salam
TypeCNAME
const TypeCNAME: i32 = 5The example for this item is shown with the ones above: net-dns-Message.salam
TypeSOA
const TypeSOA: i32 = 6The example for this item is shown with the ones above: net-dns-Message.salam
TypePTR
const TypePTR: i32 = 12The example for this item is shown with the ones above: net-dns-Message.salam
TypeMX
const TypeMX: i32 = 15The example for this item is shown with the ones above: net-dns-Message.salam
TypeTXT
const TypeTXT: i32 = 16The example for this item is shown with the ones above: net-dns-Message.salam
TypeAAAA
const TypeAAAA: i32 = 28The example for this item is shown with the ones above: net-dns-Message.salam
ClassIN
const ClassIN: i32 = 1The example for this item is shown with the ones above: net-dns-Message.salam
Functions
EncodeQuery
func EncodeQuery(name: str, qtype: int, id: int): compress.ByteBufThe example for this item is shown with the ones above: net-dns-Message.salam
Decode
func Decode(data: void*, n: int): MessageThe example for this item is shown with the ones above: net-dns-Message.salam
Lookup
func Lookup(host: str): strThe example for this item is shown with the ones above: net-dns-Message.salam
QueryServer
func QueryServer(server: str, name: str, qtype: int, timeout_ms: int): MessageThe example for this item is shown with the ones above: net-dns-Lookup.salam
DefaultServers
func DefaultServers(): Vector<str>The example for this item is shown with the ones above: net-dns-Message.salam
LookupA
func LookupA(name: str): Vector<str>The example for this item is shown with the ones above: net-dns-Lookup.salam
LookupAAAA
func LookupAAAA(name: str): Vector<str>The example for this item is shown with the ones above: net-dns-Lookup.salam
LookupCNAME
func LookupCNAME(name: str): strThe example for this item is shown with the ones above: net-dns-Lookup.salam
LookupMX
func LookupMX(name: str): RecordsThe example for this item is shown with the ones above: net-dns-Lookup.salam
LookupTXT
func LookupTXT(name: str): Vector<str>The example for this item is shown with the ones above: net-dns-Lookup.salam
LookupPTR
func LookupPTR(ip: str): Vector<str>The example for this item is shown with the ones above: net-dns-Lookup.salam