diff --git a/util/doh.go b/util/doh.go new file mode 100644 index 0000000..012c551 --- /dev/null +++ b/util/doh.go @@ -0,0 +1,26 @@ +package util + +import ( + "log" + + "github.com/babolivier/go-doh-client" +) + +func DnsLookupOverHttps(dns string, domain string) (string, error) { + // Perform a A lookup on example.com + resolver := doh.Resolver{ + Host: dns, // Change this with your favourite DoH-compliant resolver. + Class: doh.IN, + } + + Debug(domain) + a, _, err := resolver.LookupA(domain) + if err != nil { + log.Println("Error looking up dns. ", err) + return "", err + } + + ip := a[0].IP4 + + return ip, nil +} diff --git a/util/util.go b/util/util.go index 030e9bf..cd36e0f 100644 --- a/util/util.go +++ b/util/util.go @@ -4,83 +4,63 @@ import ( "log" "strings" - "github.com/babolivier/go-doh-client" "github.com/xvzc/SpoofDPI/config" ) -func ExtractDomain(message *[]byte) (string) { - i := 0 - for ; i < len(*message); i++ { - if (*message)[i] == '\n' { - i++ - break; - } - } +func ExtractDomain(message *[]byte) string { + i := 0 + for ; i < len(*message); i++ { + if (*message)[i] == '\n' { + i++ + break + } + } - for ; i < len(*message); i++ { - if (*message)[i] == ' ' { - i++ - break; - } - } + for ; i < len(*message); i++ { + if (*message)[i] == ' ' { + i++ + break + } + } - j := i - for ; j < len(*message); j++ { - if (*message)[j] == '\n' { - break; - } - } + j := i + for ; j < len(*message); j++ { + if (*message)[j] == '\n' { + break + } + } - domain := strings.Split(string((*message)[i:j]), ":")[0] + domain := strings.Split(string((*message)[i:j]), ":")[0] - return strings.TrimSpace(domain) + return strings.TrimSpace(domain) } -func DnsLookupOverHttps(dns string, domain string)(string, error) { - // Perform a A lookup on example.com - resolver := doh.Resolver{ - Host: dns, // Change this with your favourite DoH-compliant resolver. - Class: doh.IN, - } +func ExtractMethod(message *[]byte) string { + i := 0 + for ; i < len(*message); i++ { + if (*message)[i] == ' ' { + break + } + } - Debug(domain) - a, _, err := resolver.LookupA(domain) - if err != nil { - log.Println("Error looking up dns. ", err) - return "", err - } + method := strings.TrimSpace(string((*message)[:i])) + Debug(method) - ip := a[0].IP4 - - return ip, nil -} - -func ExtractMethod(message *[]byte) (string) { - i := 0 - for ; i < len(*message); i++ { - if (*message)[i] == ' ' { - break; - } - } - - method := strings.TrimSpace(string((*message)[:i])) - Debug(method) - - return strings.ToUpper(method) + return strings.ToUpper(method) } func Debug(v ...interface{}) { - if config.GetConfig().Debug == false { - return - } + if config.GetConfig().Debug == false { + return + } - log.Println(v...) + log.Println(v...) } -func BytesToChunks(buf []byte) ([][]byte) { - if len(buf) < 1 { - return [][]byte{buf} - } +func BytesToChunks(buf []byte) [][]byte { + if len(buf) < 1 { + return [][]byte{buf} + } - return [][]byte{buf[:1], buf[1:]} + return [][]byte{buf[:1], buf[1:]} }