MAC vendor lookup: Difference between revisions

m
(→‎{{header|AppleScript}}: Do the appending and delaying in AS instead of shell)
m (→‎{{header|Wren}}: Minor tidy)
 
(44 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 61:
23-45-67 N/A
foobar N/A</pre>
 
=={{header|APL}}==
{{works with|Dyalog APL}}
{{libheader|HttpCommand}}
 
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.
 
<syntaxhighlight lang="apl">⍝load the library module
]load HttpCommand
 
⍝ define a direct function (dfn) to look up a single MAC address
vendorLookup1 ← { (HttpCommand.Get 'http://api.macvendors.com/',⍕⍵).Data }
 
⍝ define a traditional function to look up all the MAC addresses in a list with
⍝ a delay between calls
 
⍝ The header says that the function is named vendorLookup, it takes a single
⍝ parameter which we call macList, and the value of the local variable
⍝ vendors will become the function's return value
∇ vendors ← vendorLookup macList
⍝ look up the first vendor and put it into an array in our return var
vendors ← ⊆vendorLookup1 1↑macList
⍝ Loop over the rest of the array
:For burger :In 1↓macList
⎕DL 2 ⍝ wait 2 seconds
vendors ⍪← ⊆vendorLookup1 burger ⍝ then look up the next vendor and append
:EndFor
 
⍝ demo data
macList ← '88:53:2E:67:07:BE' 'D4:F4:6F:C9:EF:8D' 'FC:FB:FB:01:FA:21'
macList ⍪← '4c:72:b9:56:fe:bc' '00-14-22-01-23-45'
 
⍝ look up the vendors (takes a while with the 2-second delay between lookups)
vendorList ← vendorLookup macList
 
⍝ 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.
{(1⌷⍴⍵) 1 ⍴ ⍵} vendorList</syntaxhighlight>
 
{{Out}}
<pre> Intel Corporate
Apple, Inc.
Cisco Systems, Inc
PEGATRON CORPORATION
Dell Inc.
</pre>
 
=={{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)
global apiRoot
return do shell script "curl " & apiRoot & "/" & macAddr
end lookupVendor
 
set table to { lookupVendor(first item of macList) }
repeat with burger in macList's items 2 thru -1
set end of table to do shell script "curl " & apiRoot & "/" & burger
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 97 ⟶ 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 109 ⟶ 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 130 ⟶ 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 214 ⟶ 307:
return EXIT_FAILURE;
}
</syntaxhighlight>
</lang>
Invocation and output :
<pre>
Line 225 ⟶ 318:
=={{header|C sharp|C#}}==
 
<langsyntaxhighlight lang="csharp">using System;
using System.Net;
using System.Net.Http;
Line 244 ⟶ 337:
Console.ReadLine();
}
}</langsyntaxhighlight>
 
{{out}}
Line 256 ⟶ 349:
=={{header|C++}}==
{{libheader|Boost}}
<langsyntaxhighlight lang="cpp">// This code is based on the example 'Simple HTTP Client' included with
// the Boost documentation.
 
Line 318 ⟶ 411:
}
return EXIT_FAILURE;
}</langsyntaxhighlight>
 
{{out}}
Line 327 ⟶ 420:
 
=={{header|Common Lisp}}==
<langsyntaxhighlight Commonlang="common Lisplisp">(quicklisp:quickload :Drakma) ; or load it in another way
 
(defun mac-vendor (mac)
Line 336 ⟶ 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 372 ⟶ 465:
Writeln(macLookUp('BC:5F:F4'));
readln;
end.</langsyntaxhighlight>
{{out}}
<pre>Samsung Electronics Co.,Ltd
Line 379 ⟶ 472:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: accessors calendar continuations http.client io kernel
sequences threads ;
 
Line 389 ⟶ 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 398 ⟶ 491:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">Function pipeout(Byval s As String = "") Byref As String
Var f = Freefile
Dim As String tmp
Line 423 ⟶ 516:
Next i
Sleep
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 433 ⟶ 526:
 
=={{header|Free Pascal}}==
<langsyntaxhighlight lang="pascal">program MACVendorLookup;
 
uses
Line 456 ⟶ 549:
end;
end;
end.</langsyntaxhighlight>
 
{{out}}
Line 468 ⟶ 561:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 488 ⟶ 581:
fmt.Println(macLookUp("BC:5F:F4"))
}
</syntaxhighlight>
</lang>
{{Out}}
<pre>Samsung Electronics Co.,Ltd
Line 499 ⟶ 592:
{{libheader|http-client}}
 
<langsyntaxhighlight lang="haskell">#!/usr/bin/env stack
{- stack
script
Line 545 ⟶ 638:
putStr $ printf "%-17s" mac ++ " = "
vendor <- lookupMac mgr mac
putStrLn vendor</langsyntaxhighlight>
 
{{Out}}
Line 558 ⟶ 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 616 ⟶ 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 626 ⟶ 775:
 
findmac();
</syntaxhighlight>
</lang>
{{out}}
<pre>Intel Corporate</pre>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia"># v0.6.0
 
using Requests
Line 645 ⟶ 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 654 ⟶ 803:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.net.URL
Line 663 ⟶ 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 672 ⟶ 821:
Apple, Inc.
</pre>
 
=={{header|Logo}}==
{{works with|UCB Logo}}
<syntaxhighlight 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]
 
to lookup_vendor :mac
output first shell (sentence [curl -s] (word :api_root :mac) [&& echo])
end
 
print lookup_vendor first :mac_list
foreach butfirst :mac_list [
wait 90
print lookup_vendor ?
]
bye
bye</syntaxhighlight>
{{Out}}
<pre>Intel Corporate
Apple, Inc.
Cisco Systems, Inc
PEGATRON CORPORATION
Dell Inc.</pre>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">-- Requires LuaSocket extension by Lua
-- Created by James A. Donnell Jr.
-- www.JamesDonnell.com
Line 687 ⟶ 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 707 ⟶ 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 734 ⟶ 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 771 ⟶ 1,008:
 
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 783 ⟶ 1,020:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/env perl -T
use 5v5.018_00218.2;
use warnings;
use LWP;
use Time::HiRes qw(sleep);
 
our $VERSION = 1.000_000;
Line 792 ⟶ 1,030:
my $ua = LWP::UserAgent->new;
 
no warnings 'qw';
my @macs = (
my @macs = qw(
'FC-A1-3EFC:FB:FB:01:FA:21', '00,0d,4b',
FC-A1-3EFC:FB:FB:01:FA:21 00,0d,4b
'Rhubarb', '00-14-22-01-23-45',
'10:dd:b1',Rhubarb 'D4:F4:6F:C9:EF:8D', 00-14-22-01-23-45
'FC-A1-3E',10:dd:b1 '88D4:53F4:2E6F:67C9:07EF:BE',8D
'23:45:67',FC-A1-3E 'FC88:FB53:FB2E:0167:FA07:21',BE
23:45:67 FC:FB:FB:01:FA:21
'BC:5F:F4',
BC:5F:F4
);
 
forwhile (my $mac (= shift @macs) {
my $vendor = get_mac_vendor($mac);
if ($vendor) {
say "$mac = $vendor";
}
sleep 1.5 if @macs;
}
 
Line 848 ⟶ 1,088:
# }
# return;
#}</langsyntaxhighlight>
 
{{out}}
Line 863 ⟶ 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 884 ⟶ 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 890 ⟶ 1,130:
</pre>
 
=={{header|PicoLispPHP}}==
{{trans|AppleScript}}
<lang PicoLisp>(load "@lib/http.l")
<syntaxhighlight lang="php"><?php
$apiRoot = "https://api.macvendors.com";
$macList = array("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");
 
$curl = curl_init();
(de maclookup (M)
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
(client "api.macvendors.com" 80
foreach ($macList as $burger) {
M
curl_setopt($curl, CURLOPT_URL, "$apiRoot/$burger");
(while (line))
echo(curl_exec($curl));
(line T) ) )
echo("\n");
(test
sleep(2);
"Intel Corporate"
}
(maclookup "88:53:2E:67:07:BE") )
curl_close($curl);
(test
?></syntaxhighlight>
"Apple, Inc."
 
(maclookup "D4:F4:6F:C9:EF:8D") )</lang>
{{Out}}
<pre>Intel Corporate
Apple, Inc.
Cisco Systems, Inc
PEGATRON CORPORATION
Dell Inc.</pre>
 
=={{header|PowerShell}}==
{{trans|AppleScript}}
<syntaxhighlight 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",
"00-14-22-01-23-45")
 
$macAddresses | % {
(Invoke-WebRequest "$apiRoot/$_").Content
Start-Sleep 1.5
}</syntaxhighlight>
 
{{Out}}
<pre>Intel Corporate
Apple, Inc.
Cisco Systems, Inc
PEGATRON CORPORATION
Dell Inc.</pre>
 
=={{header|Python}}==
<lang python>import {{libheader|requests}}
 
<syntaxhighlight 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 920 ⟶ 1,191:
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">#lang racket
 
(require net/url)
Line 933 ⟶ 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 945 ⟶ 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 969 ⟶ 1,240:
00:0d:4b
23:45:67
> -> $mac { say lookup $mac }</langsyntaxhighlight>
{{out}}
<pre>ASRock Incorporation
Line 979 ⟶ 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 987 ⟶ 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,012 ⟶ 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,019 ⟶ 1,290:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project: MAC Vendor Lookup
 
Line 1,031 ⟶ 1,302:
url = download("api.macvendors.com/" + mac)
see url + nl
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,041 ⟶ 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,048 ⟶ 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,057 ⟶ 1,328:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">extern crate reqwest;
 
use std::{thread, time};
Line 1,108 ⟶ 1,379:
}
}
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,118 ⟶ 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,125 ⟶ 1,396:
 
macs.foreach(mac => println(lookupVendor(mac)))
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
{{trans|Applescript}}
{{works with|Chicken Scheme}}
{{libheader|http-client}}
<syntaxhighlight 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"
"FC:FB:FB:01:FA:21" "4c:72:b9:56:fe:bc"
"00-14-22-01-23-45"))
 
(define get-vendor (lambda (mac-address)
(with-input-from-request (string-append api-root "/" mac-address)
#f read-string)))
 
(display (get-vendor (car mac-addresses)))
(newline)
(map (lambda (burger) (sleep 2) (display (get-vendor burger)) (newline))
(cdr mac-addresses))</syntaxhighlight>
{{Out}}
<pre>Intel Corporate
Apple, Inc.
Cisco Systems, Inc
PEGATRON CORPORATION
Dell Inc.</pre>
 
=={{header|Tcl}}==
<langsyntaxhighlight Tcllang="tcl">package require http
 
# finally is a bit like go's defer
Line 1,147 ⟶ 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,155 ⟶ 1,451:
=={{header|UNIX Shell}}==
{{trans|AppleScript}}
{{works with|Bourne Again SHell}}
Surprising that nobody had implemented the Bash / Shell version yet although the majority of the implementations on this page are just leveraging it.
{{works with|Korn Shell|93+}}
{{works with|Z Shell}}
Surprising that nobody had implemented the Bash / Shell version yet.
<syntaxhighlight 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)
 
lookup() {
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</syntaxhighlight>
 
It can be made to work in a pure-POSIX shell without array variables:
{{works with|Bourne Shell}}
{{works with|Almquist Shell}}
<syntaxhighlight 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
sleep 2
curl -s "http://api.macvendors.com/$burger" && echo
done</syntaxhighlight>
 
And hey, just for completeness, let's toss in a [t]csh version:
 
{{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>
 
Shell one liners can be hard to read but are incredibly compact and powerful.
<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 curl http://api.macvendors.com/$burger && sleep 5 && echo;done
</lang>
{{out}}
All the above versions have identical output:
 
<pre>
Intel Corporate
Line 1,171 ⟶ 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,183 ⟶ 1,523:
wscript.echo mac & " -> " & WebRequest.ResponseText
next
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,189 ⟶ 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,195 ⟶ 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,202 ⟶ 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,236 ⟶ 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,243 ⟶ 1,648:
vm.InterpretFile(fileName)
vm.Free()
}</langsyntaxhighlight>
 
{{out}}
Line 1,254 ⟶ 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,262 ⟶ 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,274 ⟶ 1,679:
 
=={{header|Zoea}}==
<syntaxhighlight lang="zoea">
<lang Zoea>
program: mac_vendor_lookup
 
Line 1,282 ⟶ 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