MAC vendor lookup: Difference between revisions

Content added Content deleted
m (added whitespace for the TOC.)
(Added Wren)
Line 974: Line 974:
<pre>00-14-22-01-23-45 Dell Inc.
<pre>00-14-22-01-23-45 Dell Inc.
88:53:2E:67:07:BE Intel Corporate</pre>
88:53:2E:67:07:BE Intel Corporate</pre>

=={{header|Wren}}==
Wren CLI doesn't currently expose a way to look up a MAC address.

However, if Wren is embedded in (say) a suitable Go program, then we can ask the latter to do it for us.
<lang ecmascript>/* mac_vendor_lookup.wren */
class MAC {
foreign static lookup(address)
}

System.print(MAC.lookup("FC:FB:FB:01:FA:21"))</lang>

which we embed in the following Go program and run it.
{{libheader|WrenGo}}
<lang go>/* mac_vendor_lookup.go */
package main

import (
wren "github.com/crazyinfin8/WrenGo"
"io/ioutil"
"net/http"
)

type any = interface{}

func macLookup(vm *wren.VM, parameters []any) (any, error) {
mac := parameters[1].(string)
resp, _ := http.Get("http://api.macvendors.com/" + mac)
body, _ := ioutil.ReadAll(resp.Body)
return string(body), nil
}

func main() {
vm := wren.NewVM()
fileName := "mac_vendor_lookup.wren"
methodMap := wren.MethodMap{"static lookup(_)": macLookup}
classMap := wren.ClassMap{"MAC": wren.NewClass(nil, nil, methodMap)}
module := wren.NewModule(classMap)
vm.SetModule(fileName, module)
vm.InterpretFile(fileName)
vm.Free()
}</lang>

{{out}}
<pre>
Cisco Systems, Inc
</pre>


=={{header|zkl}}==
=={{header|zkl}}==