本文整理汇总了Golang中net.LookupTXT函数的典型用法代码示例。如果您正苦于以下问题:Golang LookupTXT函数的具体用法?Golang LookupTXT怎么用?Golang LookupTXT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LookupTXT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TraverseSPF
// Recursively takes an spf record and resolves into a list of IP addresses
//TODO: Handle IPv6 addresses. Currently ignoring due to the huge
// performance hit. Too slow.
func TraverseSPF(records []string) string {
var expandedSPF string
var recordArr []string
for _, record := range records {
// Skip non SPF TXT records
if !strings.Contains(record, "spf") {
continue
}
//fmt.Printf("\nExpanding \"%s\"", record)
// Explode record on spaces
recordArr = strings.Split(record, " ")
//fmt.Printf("\nSplit \"%q\"", recordArr)
// Loop through all directives and process
for _, r := range recordArr {
// Lines start with - are fails
if strings.HasPrefix(r, "-") {
continue
}
// Get TXT records and for each include
if strings.Contains(r, "include:") {
temp := strings.Replace(strings.Replace(strings.Replace(r, "+include:", "", -1), "~include:", "", -1), "include:", "", -1)
passArr, _ := net.LookupTXT(temp)
//fmt.Printf("\n Found include")
expandedSPF = expandedSPF + " " + TraverseSPF(passArr)
// Expand redirects
} else if strings.Contains(r, "redirect=") {
passArr, _ := net.LookupTXT(strings.Replace(r, "redirect=", "", -1))
//fmt.Printf("\n Found redirect")
expandedSPF = expandedSPF + " " + TraverseSPF(passArr)
// If contains mx get mx records
} else if strings.Contains(r, "mx:") {
//TODO: Add MX expansion
// Currently this is just ignoring mx records as if they were invalid
//passArr, _ := net.LookupMX(strings.Replace(r, "mx:", "", -1))
//fmt.Printf("\n Found mx")
//expandedSPF = expandedSPF + " " + TraverseSPF(passArr)
} else {
//fmt.Printf("\n Nothing to expand")
expandedSPF = expandedSPF + " " + r
}
}
}
return expandedSPF
}
示例2: main
func main() {
txt, err := net.LookupTXT("rs.dns-oarc.net")
if err != nil {
fmt.Println(err)
}
fmt.Printf("%v", txt)
}
示例3: LookupRBL
func (rbl *RBL) LookupRBL(ip net.IP) (RBLResult, error) {
res := RBLResult{
Listed: false,
Ip: ip,
Zone: rbl.Zone,
Text: "",
}
query, err := rbl.query(ip)
if err != nil {
return res, err
}
addrs, err := net.LookupHost(query)
reg, _ := regexp.Compile("(?i:no such host)")
if err != nil && reg.FindStringIndex(err.Error()) == nil {
return res, err
}
if len(addrs) > 0 {
res.Listed = true
text, err := net.LookupTXT(query)
if err == nil {
res.Text = strings.Join(text, "\n")
}
}
return res, nil
}
示例4: runTraceroute
func runTraceroute(targetHost string, ipChan chan []string, waitChan chan int) {
app := "traceroute"
arg0 := "-f" //-f 2
arg1 := "1" //first ttl
arg2 := "-m"
arg3 := "25" //max ttl
arg4 := "-q"
arg5 := "3" //number of tries per hop
arg6 := "-w"
arg7 := "2" //wait time (in seconds)
arg8 := "-n" //no dns resolution
arg9 := "64" //packet size, bytes
cmd := exec.Command(app, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, targetHost, arg9) //execute the commands above, with the host passed
out, err := cmd.Output() //output the results of the command
if err != nil {
fmt.Printf(err.Error())
return
}
//fmt.Printf("%s\n", string(out))
traceResult := findIPaddr(string(out))
//fmt.Printf("%q\n", traceResult)
var ipArray = make([]string, 0)
dnsPtr := ""
asnResult := ""
for i := 2; i < len(traceResult); i++ {
currIpAddr := traceResult[i][0]
reverseDNSaddr, _ := net.LookupAddr(currIpAddr)
if len(reverseDNSaddr) > 0 {
//fmt.Printf("%s\n", reverseDNSaddr[0])
dnsPtr = reverseDNSaddr[0] //if it has a PTR, put it in the PTR array section
} else {
dnsPtr = "noPTR" //everything that does not have a PTR listed
}
reverseIPaddrResult := reverseIPaddr(currIpAddr) //call the function to reverse the IP address
dnsQueryAddress := reverseIPaddrResult + ".origin.asn.cymru.com" //query team cymru database for IP to ASN
ipToAsnLookup, _ := net.LookupTXT(dnsQueryAddress) //get TXT record result
if len(ipToAsnLookup) > 0 {
asnIndex := strings.Index(ipToAsnLookup[0], " ") //if so, parse out the ASN from the result
queryString := ipToAsnLookup[0]
asnResult = queryString[0:asnIndex]
} else {
asnResult = "noASN"
}
ipRowString := currIpAddr + "," + dnsPtr + "," + asnResult
ipArray = append(ipArray, ipRowString)
}
//fmt.Printf("%d\n", len(traceIpArray))
//fmt.Printf("%q\n", ipArray)
ipChan <- ipArray
waitChan <- 1
return
}
示例5: txt
func (d Domain) txt() string {
addrs, err := net.LookupTXT(d.domain)
if err != nil {
return "\nTXT records\n" +
"--\n" + err.Error()
}
records := "\nTXT records\n" +
"--\n"
for _, val := range addrs {
records += val + "\n"
}
return records
}
示例6: resourceDnsTxtRecordCreate
func resourceDnsTxtRecordCreate(d *schema.ResourceData, meta interface{}) error {
d.SetId(d.Get("name").(string))
records, err := net.LookupTXT(d.Id())
if err != nil {
return err
}
if len(records) > 0 {
d.Set("record", records[0])
}
d.Set("records", records)
return nil
}
示例7: dataSourceDnsTxtRecordRead
func dataSourceDnsTxtRecordRead(d *schema.ResourceData, meta interface{}) error {
records, err := net.LookupTXT(d.Get("host").(string))
if err != nil {
return err
}
if len(records) > 0 {
d.Set("record", records[0])
} else {
d.Set("record", "")
}
d.Set("records", records)
return nil
}
示例8: MustResolveOneTXTByName
// MustResolveOneIPByName takes in a string and returns the single
// string value for the IP which is being resolved.
// If it fails, or returns other values, panic
func MustResolveOneTXTByName(name string) string {
// Do the resolve
t, err := net.LookupTXT(name)
// Check the initial error and panic if need be
if err != nil {
panic(err)
}
// Check for multiple return values
if len(t) != 1 {
panic(fmt.Errorf("Invalid response: %v", t))
}
// Return the single value
return t[0]
}
示例9: CountryForIPString
func CountryForIPString(ipstr string) (country string, err error) {
rev, err := reverseIP(ipstr)
if err != nil {
return "", err
}
query := fmt.Sprintf("%s.%s", rev, *flCountriesZone)
txtList, err := net.LookupTXT(query)
if err != nil {
return "", err
}
if len(txtList) > 0 {
return strings.ToUpper(txtList[0]), nil
}
return "", fmt.Errorf("No TXT records (and no error) for: %s", query)
}
示例10: resourceDnsTxtRecordRead
func resourceDnsTxtRecordRead(d *schema.ResourceData, meta interface{}) error {
// Read if forcing an update, or we haven't yet read any records
if d.Get("update").(bool) {
records, err := net.LookupTXT(d.Id())
if err != nil {
return err
}
if len(records) > 0 {
d.Set("record", records[0])
}
d.Set("records", records)
}
return nil
}
示例11: ResolveOneTXTByName
// ResolveOneIPByName takes in a string and returns a string and error
// indicator. The error indicator is used if the resolve fails or returns
// multiple values.
func ResolveOneTXTByName(name string) (string, error) {
// Do the resolve
t, err := net.LookupTXT(name)
// Check the initial error and return that if present
if err != nil {
return "", err
}
// Check for multiple IPs. If so, send back an error w/ "Multiple IPs returned"
if len(t) != 1 {
err = fmt.Errorf("Multiple TXT records returned")
return "", err
}
// Return the single value
return t[0], nil
}
示例12: txt
func txt(host string) (data []byte, err error) {
txts, err := net.LookupTXT(host)
if err != nil {
err = os.ErrNotExist
return
}
buf := bytes.NewBuffer(make([]byte, 0, len(txts)*80))
for _, txt := range txts {
buf.WriteString(txt)
buf.WriteByte('\n')
}
data = buf.Bytes()
return
}
示例13: Query
func Query(hash []byte) (*Response, error) {
txts, err := net.LookupTXT(dnsname(hash))
if err != nil {
if isnxdomain(err) {
return nil, nil
}
return nil, err
}
if len(txts) != 1 {
return nil, errMultipleRecords
}
return parseResponse(txts[0])
}
示例14: GetPksAuthTXTRecord
func GetPksAuthTXTRecord(domain string) (pksAuth PksAuthTXT, err error) {
txts, err1 := net.LookupTXT(domain)
found := false
if err1 != nil {
log.Println(err1)
err = err1
return
}
net.LookupAddr(domain)
for _, r := range txts {
//log.Println("TXT of " + domain + " : " + r)
rcds := strings.Split(r, "=")
if len(rcds) != 2 {
log.Println("Not Found = in TXT Record of " + domain)
} else if rcds[0] != "pks" {
log.Println("pks not found in TXT Record of " + domain)
} else {
rcds = strings.Split(rcds[1], " ")
if len(rcds) != 3 {
log.Println("Not Enough values in TXT Record of domain " + domain)
} else {
pksAuth.authAddr = rcds[0]
//fmt.Println("pks_Addr=", rcds[0])
//fmt.Println("key_FingerPrint=", rcds[1])
pksAuth.keyFingerPrint = rcds[1]
since, err2 := strconv.Atoi(rcds[2])
if err2 != nil {
log.Println(err2)
err = err2
return
}
pksAuth.since = int64(since)
found = true
break
//fmt.Println("time=", time.Unix(int64(since), 0))
}
}
}
if found == false {
err = errors.New("TXT Record of domain " + domain + "doesnt contain valid pksAuth Record")
return
}
return
}
示例15: ltxt
func ltxt(domain string) {
txts, err := net.LookupTXT(domain)
if err != nil {
//fmt.Printf("err:%s\n", err)
return
}
fmt.Printf("-----------------\n")
fmt.Printf(" Information TXT \n")
fmt.Printf("-----------------\n")
for _, txt := range txts {
fmt.Printf("\t%s\n", txt)
}
}