MAC vendor lookup: Difference between revisions

m
(→‎{{header|APL}}: formatting.)
m (→‎{{header|Wren}}: Minor tidy)
 
(30 intermediate revisions by 11 users not shown)
Line 19:
=={{header|Ada}}==
{{libheader|AWS}}
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO;
 
with AWS.Client;
Line 52:
Lookup ("23-45-67"); delay 1.500;
Lookup ("foobar");
end MAC_Vendor;</langsyntaxhighlight>
{{out}}
<pre>88:53:2E:67:07:BE Intel Corporate
Line 68:
Normally something like this would just be mapping the lookup across an array, but that doesn't let us control the timing of the request dispatch. To insert a delay between requests we have to create a traditional function ("tradfn") with a for loop.
 
<langsyntaxhighlight lang="apl">⍝load the library module
]load HttpCommand
 
Line 82:
∇ vendors ← vendorLookup macList
⍝ look up the first vendor and put it into an array in our return var
vendors ← ⊆vendorLookup1 macList[1] 1↑macList
⍝ Loop over the rest of the array (1↓ removes the first item)
:For burger :In 1↓macList
⎕DL 2 ⍝ wait 2 seconds
Line 100:
⍝ the result is an array (a 1-row by N-column matrix). to print out one vendor
⍝ per line, we reshape it to be N rows by 1 column instead.
⎕←{(⍴ vendorList1⌷⍴⍵)[1] 1 ⍴ ⍵} vendorList</langsyntaxhighlight>
 
{{Out}}
Line 112:
=={{header|AppleScript}}==
<langsyntaxhighlight AppleScriptlang="applescript">set apiRoot to "https://api.macvendors.com"
set macList to {"88:53:2E:67:07:BE", "D4:F4:6F:C9:EF:8D", ¬
"FC:FB:FB:01:FA:21", "4c:72:b9:56:fe:bc", "00-14-22-01-23-45"}
 
on lookupVendor(macAddr)
set table to {}
global apiRoot
repeat with burger in macList
set end of table toreturn do shell script "curl " & apiRoot & "/" & burgermacAddr
end lookupVendor
 
set table to { lookupVendor(first item of macList) }
repeat with burger in macList's items 2 thru -1
delay 1.5
set end of table to lookupVendor(burger)
end repeat
 
set text item delimiters to linefeed
return table as string
</syntaxhighlight>
</lang>
 
If this is part of a larger script you probably want to save and restore the text item delimiters:
 
<langsyntaxhighlight lang="applescript">set savedTID to text item delimiters
set text item delimiters to linefeed
set tableText to table as string
set text item delimiters to savedTID
return tableText</langsyntaxhighlight>
 
{{out}}
Line 145 ⟶ 150:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">loop ["FC-A1-3E" "FC:FB:FB:01:FA:21" "BC:5F:F4"] 'mac [
print [mac "=>" read ~"http://api.macvendors.com/|mac|"]
pause 1500
]</langsyntaxhighlight>
 
{{out}}
Line 157 ⟶ 162:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">macLookup(MAC){
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("GET", "http://api.macvendors.com/" MAC)
WebRequest.Send()
return WebRequest.ResponseText
}</langsyntaxhighlight>
Examples:<langsyntaxhighlight AutoHotkeylang="autohotkey">MsgBox % macLookup("00-14-22-01-23-45")</langsyntaxhighlight>
Outputs:<pre>Dell Inc.</pre>
 
=={{header|BaCon}}==
This code requires BaCon 3.8.2 or higher.
<langsyntaxhighlight lang="bacon">OPTION TLS TRUE
 
website$ = "api.macvendors.com"
Line 178 ⟶ 183:
CLOSE NETWORK mynet
 
PRINT TOKEN$(info$, 2, "\r\n\r\n")</langsyntaxhighlight>
{{out}}
<pre>Hon Hai Precision Ind. Co.,Ltd.</pre>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> DIM Block% 599 : REM Memory buffer to receive GET info
INSTALL @lib$ + "SOCKLIB" : PROC_initsockets
READ Mac$
WHILE Mac$ > ""
WAIT 100 : REM 1 sec pause to avoid 'Too Many Requests' errors
Socket=FN_tcpconnect("api.macvendors.com", "80")
I%=FN_writelinesocket(Socket, "GET /" + Mac$ + " HTTP/1.0")
I%=FN_writelinesocket(Socket, "")
REPEAT N%=FN_readsocket(Socket, Block%, 600) UNTIL N% > 0
PROC_closesocket(Socket)
PRINT Mac$ TAB(24);
CASE LEFT$($(Block% + 9), 3) OF
WHEN "200"
Block%?N%=0 : REM Add terminating 0x00
REPEAT N%-=1 UNTIL Block%?N% < 32 : REM Leave only last line
PRINT $$(Block% + N% + 1) : REM Print string from memory
WHEN "404"
PRINT "N/A"
OTHERWISE
PRINT "ERROR"
ENDCASE
READ Mac$
ENDWHILE
PROC_exitsockets
END
DATA 88:53:2E:67:07:BE, FC:FB:FB:01:FA:21, D4:F4:6F:C9:EF:8D, 10-11-22-33-44-55,</syntaxhighlight>
{{out}}
 
<pre>
88:53:2E:67:07:BE Intel Corporate
FC:FB:FB:01:FA:21 Cisco Systems, Inc
D4:F4:6F:C9:EF:8D Apple, Inc.
10-11-22-33-44-55 N/A
</pre>
 
=={{header|C}}==
Takes MAC address as input, prints usage on incorrect invocation, requires [https://curl.haxx.se/libcurl/ libcurl]
<syntaxhighlight lang="c">
<lang C>
#include <curl/curl.h>
#include <string.h>
Line 262 ⟶ 307:
return EXIT_FAILURE;
}
</syntaxhighlight>
</lang>
Invocation and output :
<pre>
Line 273 ⟶ 318:
=={{header|C sharp|C#}}==
 
<langsyntaxhighlight lang="csharp">using System;
using System.Net;
using System.Net.Http;
Line 292 ⟶ 337:
Console.ReadLine();
}
}</langsyntaxhighlight>
 
{{out}}
Line 304 ⟶ 349:
=={{header|C++}}==
{{libheader|Boost}}
<langsyntaxhighlight lang="cpp">// This code is based on the example 'Simple HTTP Client' included with
// the Boost documentation.
 
Line 366 ⟶ 411:
}
return EXIT_FAILURE;
}</langsyntaxhighlight>
 
{{out}}
Line 375 ⟶ 420:
 
=={{header|Common Lisp}}==
<langsyntaxhighlight Commonlang="common Lisplisp">(quicklisp:quickload :Drakma) ; or load it in another way
 
(defun mac-vendor (mac)
Line 384 ⟶ 429:
(format t "~%Vendor is ~a" vendor)
(error "~%Not a MAC address: ~a" mac))))
</syntaxhighlight>
</lang>
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{libheader| IdHttp}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program MAC_Vendor_Lookup;
 
Line 420 ⟶ 465:
Writeln(macLookUp('BC:5F:F4'));
readln;
end.</langsyntaxhighlight>
{{out}}
<pre>Samsung Electronics Co.,Ltd
Line 427 ⟶ 472:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: accessors calendar continuations http.client io kernel
sequences threads ;
 
Line 437 ⟶ 482:
"FC:FB:FB:01:FA:21"
"10-11-22-33-44-55-66"
[ mac-vendor print 1 seconds sleep ] tri@</langsyntaxhighlight>
{{out}}
<pre>
Line 446 ⟶ 491:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">Function pipeout(Byval s As String = "") Byref As String
Var f = Freefile
Dim As String tmp
Line 471 ⟶ 516:
Next i
Sleep
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 481 ⟶ 526:
 
=={{header|Free Pascal}}==
<langsyntaxhighlight lang="pascal">program MACVendorLookup;
 
uses
Line 504 ⟶ 549:
end;
end;
end.</langsyntaxhighlight>
 
{{out}}
Line 516 ⟶ 561:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 536 ⟶ 581:
fmt.Println(macLookUp("BC:5F:F4"))
}
</syntaxhighlight>
</lang>
{{Out}}
<pre>Samsung Electronics Co.,Ltd
Line 547 ⟶ 592:
{{libheader|http-client}}
 
<langsyntaxhighlight lang="haskell">#!/usr/bin/env stack
{- stack
script
Line 593 ⟶ 638:
putStr $ printf "%-17s" mac ++ " = "
vendor <- lookupMac mgr mac
putStrLn vendor</langsyntaxhighlight>
 
{{Out}}
Line 606 ⟶ 651:
=={{header|J}}==
'''Solution
<langsyntaxhighlight lang="j">require 'web/gethttp'
lookupMACvendor=: [: gethttp 'http://api.macvendors.com/'&,</langsyntaxhighlight>
'''Example Usage
<langsyntaxhighlight lang="j"> addr=: '88:53:2E:67:07:BE';'FC:FB:FB:01:FA:21';'D4:F4:6F:C9:EF:8D';'23:45:67'
(,&' ' , lookupMACvendor)&> addr
88:53:2E:67:07:BE Intel Corporate
FC:FB:FB:01:FA:21 Cisco Systems, Inc
D4:F4:6F:C9:EF:8D Apple, Inc.
23:45:67 Vendor not found</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">package com.jamesdonnell.MACVendor;
 
import java.io.BufferedReader;
Line 664 ⟶ 709:
}
}
}</langsyntaxhighlight>
 
===Java 11===
<syntaxhighlight lang="java">
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.List;
import java.util.concurrent.TimeUnit;
 
public final class MacVendorLookup {
 
public static void main(String[] aArgs) throws InterruptedException, IOException {
for ( String macAddress : macAddresses ) {
HttpResponse<String> response = getMacVendor(macAddress);
System.out.println(macAddress + " " + response.statusCode() + " " + response.body());
TimeUnit.SECONDS.sleep(2);
}
}
 
private static HttpResponse<String> getMacVendor(String aMacAddress) throws IOException, InterruptedException {
URI uri = URI.create(BASE_URL + aMacAddress);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest
.newBuilder()
.uri(uri)
.header("accept", "application/json")
.GET()
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
return response;
}
private static final String BASE_URL = "http://api.macvendors.com/";
private static final List<String> macAddresses = List.of("88:53:2E:67:07:BE",
"D4:F4:6F:C9:EF:8D",
"FC:FB:FB:01:FA:21",
"4c:72:b9:56:fe:bc",
"00-14-22-01-23-45"
);
}
</syntaxhighlight>
{{ out }}
<pre>
88:53:2E:67:07:BE 200 Intel Corporate
D4:F4:6F:C9:EF:8D 200 Apple, Inc.
FC:FB:FB:01:FA:21 200 Cisco Systems, Inc
4c:72:b9:56:fe:bc 200 PEGATRON CORPORATION
00-14-22-01-23-45 200 Dell Inc.
</pre>
 
=={{header|Javascript}}==
<langsyntaxhighlight lang="javascript">
var mac = "88:53:2E:67:07:BE";
function findmac(){
Line 674 ⟶ 775:
 
findmac();
</syntaxhighlight>
</lang>
{{out}}
<pre>Intel Corporate</pre>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia"># v0.6.0
 
using Requests
Line 693 ⟶ 794:
for addr in ["88:53:2E:67:07:BE", "FC:FB:FB:01:FA:21", "D4:F4:6F:C9:EF:8D", "23:45:67"]
println("$addr -> ", getvendor(addr))
end</langsyntaxhighlight>
 
{{out}}
Line 702 ⟶ 803:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.net.URL
Line 711 ⟶ 812:
val macs = arrayOf("FC-A1-3E", "FC:FB:FB:01:FA:21", "88:53:2E:67:07:BE", "D4:F4:6F:C9:EF:8D")
for (mac in macs) println(lookupVendor(mac))
}</langsyntaxhighlight>
 
{{out}}
Line 723 ⟶ 824:
=={{header|Logo}}==
{{works with|UCB Logo}}
<langsyntaxhighlight lang="logo">make "api_root "http://api.macvendors.com/
make "mac_list [88:53:2E:67:07:BE D4:F4:6F:C9:EF:8D FC:FB:FB:01:FA:21
4c:72:b9:56:fe:bc 00-14-22-01-23-45]
Line 731 ⟶ 832:
end
 
foreachprint lookup_vendor first :mac_list [
foreach butfirst :mac_list [
print lookup_vendor ?
wait 90
print lookup_vendor ?
]
bye</lang>
bye</syntaxhighlight>
{{Out}}
<pre>Intel Corporate
Line 744 ⟶ 847:
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">-- Requires LuaSocket extension by Lua
-- Created by James A. Donnell Jr.
-- www.JamesDonnell.com
Line 757 ⟶ 860:
 
local macAddress = "FC-A1-3E-2A-1C-33"
print(lookup(macAddress))</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Checkit {
httpGet$=lambda$ (url$, timeout=500)->{
Line 777 ⟶ 880:
declare htmldoc nothing
}
Urls=("88:53:2E:67:07:BE", "FC:FB:FB:01:FA:21", "D4:F4:6F:C9:EF:8D", "23BC:455F:67F4")
url=each(URLs)
While Url {
Print Array$(URL),@(20), httpGet$("httphttps://api.macvendors.com/"+Array$(URL))
Wait 201500
}
}
Checkit
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">macLookup[mac_String] := Quiet[Check[Import["http://api.macvendors.com/" <> mac], "N/A"]]</langsyntaxhighlight>
Examples:<langsyntaxhighlight Mathematicalang="mathematica">macLookup["00-14-22-01-23-45"]</langsyntaxhighlight>
Outputs:<pre>Dell Inc.</pre>
 
=={{header|MiniScript}}==
This implementation is for use with the [http://miniscript.org/MiniMicro Mini Micro] version of MiniScript.
<syntaxhighlight lang="miniscript">
macList = ["88:53:2E:67:07:BE", "FC:FB:FB:01:FA:21", "00:02:55:00:00:00",
"D4:F4:6F:C9:EF:8D", "23:45:67", "18:93:D7", "1C:A6:81"]
 
for mac in macList
ret = http.get("http://api.macvendors.com/"+mac)
if ret == "HTTP/1.1 404 Not Found" then ret = "N/A"
print ret
wait 1
end for
</syntaxhighlight>
{{out}}
<pre>
Intel Corporate
Cisco Systems, Inc
IBM Corp
Apple, Inc.
N/A
Texas Instruments
HUAWEI TECHNOLOGIES CO.,LTD
</pre>
 
=={{header|Nim}}==
 
<langsyntaxhighlight Nimlang="nim">import httpclient
 
for mac in ["FC-A1-3E", "FC:FB:FB:01:FA:21", "BC:5F:F4"]:
echo newHttpClient().getContent("http://api.macvendors.com/"&mac)</langsyntaxhighlight>
 
{{out}}
Line 804 ⟶ 931:
ASRock Incorporation
</pre>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
let mactable = http get "http://standards-oui.ieee.org/oui/oui.csv" | from csv --no-infer
 
def get-mac-org [] {
let assignment = $in | str upcase | str replace --all --regex "[^A-Z0-9]" "" | str substring 0..6
$mactable | where Assignment == $assignment | try {first | get "Organization Name"} catch {"N/A"}
}
 
# Test cases from the Ada entry
let macs = [
# Should succeed
"88:53:2E:67:07:BE"
"D4:F4:6F:C9:EF:8D"
"FC:FB:FB:01:FA:21"
"4c:72:b9:56:fe:bc"
"00-14-22-01-23-45"
# Should fail
"23-45-67"
"foobar"
]
 
$macs | each {{MAC: $in, Vendor: ($in | get-mac-org)}}
</syntaxhighlight>
{{out}}
<pre>
╭───┬───────────────────┬──────────────────────╮
│ # │ MAC │ Vendor │
├───┼───────────────────┼──────────────────────┤
│ 0 │ 88:53:2E:67:07:BE │ Intel Corporate │
│ 1 │ D4:F4:6F:C9:EF:8D │ Apple, Inc. │
│ 2 │ FC:FB:FB:01:FA:21 │ Cisco Systems, Inc │
│ 3 │ 4c:72:b9:56:fe:bc │ PEGATRON CORPORATION │
│ 4 │ 00-14-22-01-23-45 │ Dell Inc. │
│ 5 │ 23-45-67 │ N/A │
│ 6 │ foobar │ N/A │
╰───┴───────────────────┴──────────────────────╯
</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">
<lang OCaml>
(* build with ocamlfind ocamlopt -package netclient -linkpkg macaddr.ml -o macaddr *)
 
Line 841 ⟶ 1,008:
 
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 853 ⟶ 1,020:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/env perl -T
use v5.18.2;
use warnings;
Line 921 ⟶ 1,088:
# }
# return;
#}</langsyntaxhighlight>
 
{{out}}
Line 936 ⟶ 1,103:
=={{header|Phix}}==
{{libheader|Phix/libcurl}}
<!--<langsyntaxhighlight Phixlang="phix">(notonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- libcurl</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">test</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"00-11-22-33-44-55-66"</span> <span style="color: #000080;font-style:italic;">-- CIMSYS Inc
Line 957 ⟶ 1,124:
<span style="color: #7060A8;">curl_easy_cleanup</span><span style="color: #0000FF;">(</span><span style="color: #000000;">curl</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">curl_global_cleanup</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 965 ⟶ 1,132:
=={{header|PHP}}==
{{trans|AppleScript}}
<langsyntaxhighlight lang="php"><?php
$apiRoot = "https://api.macvendors.com";
$macList = array("88:53:2E:67:07:BE", "D4:F4:6F:C9:EF:8D",
Line 979 ⟶ 1,146:
}
curl_close($curl);
?></langsyntaxhighlight>
 
{{Out}}
Line 990 ⟶ 1,157:
=={{header|PowerShell}}==
{{trans|AppleScript}}
<langsyntaxhighlight lang="powershell">$apiRoot = "http://api.macvendors.com"
$macAddresses = @("88:53:2E:67:07:BE", "D4:F4:6F:C9:EF:8D",
"FC:FB:FB:01:FA:21", "4c:72:b9:56:fe:bc",
Line 998 ⟶ 1,165:
(Invoke-WebRequest "$apiRoot/$_").Content
Start-Sleep 1.5
}</langsyntaxhighlight>
 
{{Out}}
Line 1,010 ⟶ 1,177:
{{libheader|requests}}
 
<langsyntaxhighlight lang="python">import requests
 
for addr in ['88:53:2E:67:07:BE', 'FC:FB:FB:01:FA:21',
'D4:F4:6F:C9:EF:8D', '23:45:67']:
vendor = requests.get('http://api.macvendors.com/' + addr).text
print(addr, vendor)</langsyntaxhighlight>
{{out}}
<pre>88:53:2E:67:07:BE Intel Corporate
Line 1,024 ⟶ 1,191:
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">#lang racket
 
(require net/url)
Line 1,037 ⟶ 1,204:
"FC:FB:FB:01:FA:21"
"D4:F4:6F:C9:EF:8D"))))
(printf "~a\t~a~%" i (lookup-MAC-address i))))</langsyntaxhighlight>
 
{{out}}
Line 1,049 ⟶ 1,216:
Apparently there is some rate limiting on place now, sleep a bit between requests.
 
<syntaxhighlight lang="raku" perl6line>use HTTP::UserAgent;
my $ua = HTTP::UserAgent.new;
Line 1,073 ⟶ 1,240:
00:0d:4b
23:45:67
> -> $mac { say lookup $mac }</langsyntaxhighlight>
{{out}}
<pre>ASRock Incorporation
Line 1,083 ⟶ 1,250:
 
=={{header|Red}}==
<langsyntaxhighlight Redlang="red">print read rejoin [http://api.macvendors.com/ ask "MAC address: "]
</syntaxhighlight>
</lang>
{{out}}
<pre>MAC address: 88:53:2E:67:07:BE
Line 1,091 ⟶ 1,258:
=={{header|REXX}}==
This REXX version only works under Microsoft Windows and Regina REXX.
<langsyntaxhighlight lang="rexx">/*REXX pgm shows a network device's manufacturer based on the Media Access Control addr.*/
win_command = 'getmac' /*name of the Microsoft Windows command*/
win_command_options = '/v /fo list' /*options of " " " */
Line 1,116 ⟶ 1,283:
if maker=. | MACaddr==. then say 'MAC address manufacturer not found.'
else say 'manufacturer for MAC address ' MACaddr " is " maker
exit 0 /*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 1,123 ⟶ 1,290:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project: MAC Vendor Lookup
 
Line 1,135 ⟶ 1,302:
url = download("api.macvendors.com/" + mac)
see url + nl
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,145 ⟶ 1,312:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">require 'net/http'
 
arr = ['88:53:2E:67:07:BE', 'FC:FB:FB:01:FA:21', 'D4:F4:6F:C9:EF:8D', '23:45:67']
Line 1,152 ⟶ 1,319:
vendor = Net::HTTP.get('api.macvendors.com', "/#{addr}/") rescue nil
puts "#{addr} #{vendor}"
end</langsyntaxhighlight>
{{out}}
<pre>88:53:2E:67:07:BE Intel Corporate
Line 1,161 ⟶ 1,328:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">extern crate reqwest;
 
use std::{thread, time};
Line 1,212 ⟶ 1,379:
}
}
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,222 ⟶ 1,389:
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">object LookUp extends App {
val macs = Seq("FC-A1-3E", "FC:FB:FB:01:FA:21", "88:53:2E:67:07:BE", "D4:F4:6F:C9:EF:8D")
 
Line 1,229 ⟶ 1,396:
 
macs.foreach(mac => println(lookupVendor(mac)))
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
Line 1,235 ⟶ 1,402:
{{works with|Chicken Scheme}}
{{libheader|http-client}}
<langsyntaxhighlight lang="scheme">(import http-client (chicken io))
(define api-root "http://api.macvendors.com")
(define mac-addresses '("88:53:2E:67:07:BE" "D4:F4:6F:C9:EF:8D"
Line 1,245 ⟶ 1,412:
#f read-string)))
 
(map (lambda (burger) (display (get-vendor burger))(car (newlinemac-addresses) (sleep 2))
(newline)
mac-addresses)</lang>
(map (lambda (burger) (sleep 2) (display (get-vendor burger)) (newline))
(cdr mac-addresses))</syntaxhighlight>
{{Out}}
<pre>Intel Corporate
Line 1,255 ⟶ 1,424:
 
=={{header|Tcl}}==
<langsyntaxhighlight Tcllang="tcl">package require http
 
# finally is a bit like go's defer
Line 1,274 ⟶ 1,443:
foreach mac {00-14-22-01-23-45 88:53:2E:67:07:BE} {
puts "$mac\t[maclookup $mac]"
}</langsyntaxhighlight>
{{out}}
Line 1,286 ⟶ 1,455:
{{works with|Z Shell}}
Surprising that nobody had implemented the Bash / Shell version yet.
<langsyntaxhighlight lang="bash">macList=(88:53:2E:67:07:BE D4:F4:6F:C9:EF:8D FC:FB:FB:01:FA:21
4c:72:b9:56:fe:bc 00-14-22-01-23-45)
 
for burger in "${macList[@]}"; do
lookup() {
curl -s "http://api.macvendors.com/$burger" && echo
curl -s "http://api.macvendors.com/$1" && echo
}
 
lookup "${macList[0${ZSH_VERSION:++1}]}"
for burger in "${macList[@]:1}"; do
sleep 2
lookup "$burger"
done</lang>
done</syntaxhighlight>
 
It can be made to work in a pure-POSIX shell without array variables:
{{works with|Bourne Shell}}
{{works with|Almquist Shell}}
<langsyntaxhighlight lang="bash">set -- 88:53:2E:67:07:BE D4:F4:6F:C9:EF:8D FC:FB:FB:01:FA:21 \
4c:72:b9:56:fe:bc 00-14-22-01-23-45
 
lookup() {
curl -s "http://api.macvendors.com/$1" && echo
}
 
lookup "$1"
shift
for burger; do
curl -s "http://api.macvendors.com/$burger" && echo
sleep 2
curl -s "http://api.macvendors.com/$burger" && echo
done</lang>
done</syntaxhighlight>
 
And hey, just for completeness, let's toss in a [t]csh version:
The output is the same either way:
 
{{works with|C Shell}}
<syntaxhighlight lang="csh">set macList=(88:53:2E:67:07:BE D4:F4:6F:C9:EF:8D FC:FB:FB:01:FA:21 \
4c:72:b9:56:fe:bc 00-14-22-01-23-45)
 
alias lookup curl -s "http://api.macvendors.com/!":1 "&&" echo
 
lookup "$macList[1]"
foreach burger ($macList[2-]:q)
sleep 2
lookup "$burger"
end</syntaxhighlight>
 
{{out}}
All the above versions have identical output:
 
<pre>
Intel Corporate
Line 1,315 ⟶ 1,511:
 
=={{header|VBScript}}==
<syntaxhighlight lang="text">
a=array("00-20-6b-ba-d0-cb","00-40-ae-04-87-86")
set WebRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
Line 1,327 ⟶ 1,523:
wscript.echo mac & " -> " & WebRequest.ResponseText
next
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,333 ⟶ 1,529:
Spacing next request...
00-40-ae-04-87-86 -> DELTA CONTROLS, INC.
</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">import net.http
import time
 
const macs =
('
FC-A1-3E
FC:FB:FB:01:FA:21
D4:F4:6F:C9:EF:8D
')
 
fn main() {
for line in macs.split('\n') {
if line !='' {
println(mac_lookup(line))
time.sleep(2 * time.second) // considerate delay between attempts
}
}
}
 
fn mac_lookup(mac string) string {
resp := http.get("http://api.macvendors.com/" + mac) or {return 'No data from server'}
return resp.body.str()
}</syntaxhighlight>
 
{{out}}
<pre>
Samsung Electronics Co.,Ltd
Cisco Systems, Inc
Apple, Inc.
</pre>
 
=={{header|Visual Basic .NET}}==
Based on the C# sample but works with .Net versions prior to Framework 4.5.<br>
Expects the address to be on the command line, if not specified, it defaults to 88:53:2E:67:07:BE.
<syntaxhighlight lang="vbnet">
' MAC Vendor lookup - based on the C# sample.
 
Imports System
Imports System.Net
 
Module LookupMac
 
Public Sub Main(args() As String)
 
Dim macAddress As String = If(args.Length < 1, "88:53:2E:67:07:BE", args(0))
Dim uri As New Uri("http://api.macvendors.com/" & WebUtility.UrlEncode(macAddress))
Dim wc As New WebClient()
Console.Out.WriteLine(macAddress & " " & wc.DownloadString(uri))
 
End Sub
 
End Module
</syntaxhighlight>
{{out}}
With no address on the command line:
<pre>
88:53:2E:67:07:BE Intel Corporate
</pre>
 
With FC:FB:FB:01:FA:21 on the command line:
<pre>
FC:FB:FB:01:FA:21 Cisco Systems, Inc
</pre>
 
Line 1,339 ⟶ 1,600:
 
However, if Wren is embedded in (say) a suitable Go program, then we can ask the latter to do it for us.
<langsyntaxhighlight ecmascriptlang="wren">/* mac_vendor_lookupMAC_vendor_lookup.wren */
class MAC {
foreign static lookup(address)
Line 1,346 ⟶ 1,607:
System.print(MAC.lookup("FC:FB:FB:01:FA:21"))
for (i in 1..1e8) {} // slow down request
System.print(MAC.lookup("23:45:67"))</langsyntaxhighlight>
 
which we embed in the following Go program and run it.
{{libheader|WrenGo}}
<langsyntaxhighlight lang="go">/* mac_vendor_lookupMAC_vendor_lookup.go */
package main
 
Line 1,380 ⟶ 1,641:
func main() {
vm := wren.NewVM()
fileName := "mac_vendor_lookupMAC_vendor_lookup.wren"
methodMap := wren.MethodMap{"static lookup(_)": macLookup}
classMap := wren.ClassMap{"MAC": wren.NewClass(nil, nil, methodMap)}
Line 1,387 ⟶ 1,648:
vm.InterpretFile(fileName)
vm.Free()
}</langsyntaxhighlight>
 
{{out}}
Line 1,398 ⟶ 1,659:
{{trans|Lua}}
Uses libcurl (the multiprotocol file transfer library) to do the web query
<langsyntaxhighlight lang="zkl">var [const] CURL=Import("zklCurl"); // libcurl
const MAC_VENDORS="http://api.macvendors.com/";
 
Line 1,406 ⟶ 1,667:
vender=vender[0].del(0,vender[1]); // remove HTTP header
vender.text; // Data --> String (Data is a byte bucket)
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">lookUp("FC-A1-3E-2A-1C-33").println();
lookUp("4c:72:b9:56:fe:bc").println();
lookUp("foobar").println();</langsyntaxhighlight>
{{out}}
<pre>
Line 1,418 ⟶ 1,679:
 
=={{header|Zoea}}==
<syntaxhighlight lang="zoea">
<lang Zoea>
program: mac_vendor_lookup
 
Line 1,426 ⟶ 1,687:
derive: 'http://api.macvendors.com/D4:F4:6F:C9:EF:8D'
output: 'Apple, Inc.'
</syntaxhighlight>
</lang>
 
=={{header|Zoea Visual}}==
[http://zoea.co.uk/examples/zv-rc/MAC_vendor_lookup.png MAC Vendor Lookup]
 
{{omit from|EasyLang|Has no internet functions}}
9,476

edits