MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / dnsResolve

Function dnsResolve

jsext/addrutil.go:89–105  ·  view source on GitHub ↗
(host string)

Source from the content-addressed store, hash-verified

87}
88
89func dnsResolve(host string) (res netip.Addr) {
90 ctx, cl := context.WithTimeout(context.Background(), 5*time.Second)
91 defer cl()
92 // lookup "ip" network for better cache coherence with other lookups,
93 // even though we actually interested only in IPv4 only
94 addrs, err := DefaultResolver.LookupNetIP(ctx, "ip", host)
95 if err != nil {
96 return
97 }
98 for _, ip := range addrs {
99 ip = ip.Unmap()
100 if ip.Is4() {
101 return ip
102 }
103 }
104 return
105}
106
107func AddDNSResolve(vm *goja.Runtime) error {
108 return vm.GlobalObject().Set("dnsResolve", func(call goja.FunctionCall) goja.Value {

Callers 3

AddDNSResolveFunction · 0.85
AddIsResolvableFunction · 0.85
AddIsInNetFunction · 0.85

Calls 1

LookupNetIPMethod · 0.65

Tested by

no test coverage detected