Created
August 26, 2016 04:24
-
-
Save shicky/0ac40e07a93ff813c9b04b850c717091 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "github.com/miekg/dns" | |
// ResolveIP resolves IP address using provided DNS server | |
func ResolveIP(url, server string) (string, error) { | |
msg := new(dns.Msg) | |
msg.Id = dns.Id() | |
msg.RecursionDesired = true | |
msg.Question = make([]dns.Question, 1) | |
msg.Question[0] = dns.Question{url + ".", dns.TypeA, dns.ClassINET} | |
in, err := dns.Exchange(msg, fmt.Sprintf("%s:53", server)) | |
if err != nil { | |
return "", err | |
} | |
answers := strings.Split(in.Answer[0].String(), "\t") | |
return answers[len(answers)-1], nil | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment