update util.go

This commit is contained in:
xvzc 2022-01-07 22:44:03 +09:00
parent 6b630e9ad6
commit 2fd2503dd5
2 changed files with 67 additions and 61 deletions

26
util/doh.go Normal file
View File

@ -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
}

View File

@ -4,30 +4,29 @@ import (
"log"
"strings"
"github.com/babolivier/go-doh-client"
"github.com/xvzc/SpoofDPI/config"
)
func ExtractDomain(message *[]byte) (string) {
func ExtractDomain(message *[]byte) string {
i := 0
for ; i < len(*message); i++ {
if (*message)[i] == '\n' {
i++
break;
break
}
}
for ; i < len(*message); i++ {
if (*message)[i] == ' ' {
i++
break;
break
}
}
j := i
for ; j < len(*message); j++ {
if (*message)[j] == '\n' {
break;
break
}
}
@ -36,30 +35,11 @@ func ExtractDomain(message *[]byte) (string) {
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,
}
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
}
func ExtractMethod(message *[]byte) (string) {
func ExtractMethod(message *[]byte) string {
i := 0
for ; i < len(*message); i++ {
if (*message)[i] == ' ' {
break;
break
}
}
@ -77,7 +57,7 @@ func Debug(v ...interface{}) {
log.Println(v...)
}
func BytesToChunks(buf []byte) ([][]byte) {
func BytesToChunks(buf []byte) [][]byte {
if len(buf) < 1 {
return [][]byte{buf}
}