Jump to content

MAC vendor lookup: Difference between revisions

→‎{{header|Wren}}: Tweaks to fit the task requirements more closely.
(Added Wren)
(→‎{{header|Wren}}: Tweaks to fit the task requirements more closely.)
Line 984:
}
 
System.print(MAC.lookup("FC:FB:FB:01:FA:21"))</lang>
for (i in 1..1e8) {} // slow down request
System.print(MAC.lookup("23:45:67"))</lang>
 
which we embed in the following Go program and run it.
Line 1,001 ⟶ 1,003:
func macLookup(vm *wren.VM, parameters []any) (any, error) {
mac := parameters[1].(string)
resp, _err := http.Get("http://api.macvendors.com/" + mac)
if err != nil {
body, _ := ioutil.ReadAll(resp.Body)
return string(body)nil, nil
}
}
body, _err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, nil
}
var vendor = string(body)
if vendor == `{"errors":{"detail":"Not Found"}}` {
return "N/A", nil
}
return vendor, nil
}
 
func main() {
Line 1,020 ⟶ 1,032:
<pre>
Cisco Systems, Inc
N/A
</pre>
 
9,486

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.