MAC vendor lookup: Difference between revisions
m
→{{header|Wren}}: Minor tidy
Thundergnat (talk | contribs) m (Thundergnat moved page MAC Vendor Lookup to MAC vendor lookup: capitalization policy (don't know how I missed this one for so long...)) |
m (→{{header|Wren}}: Minor tidy) |
||
(45 intermediate revisions by 11 users not shown) | |||
Line 19:
=={{header|Ada}}==
{{libheader|AWS}}
<
with AWS.Client;
Line 52:
Lookup ("23-45-67"); delay 1.500;
Lookup ("foobar");
end MAC_Vendor;</
{{out}}
<pre>88:53:2E:67:07:BE Intel Corporate
Line 62:
foobar N/A</pre>
=={{header|
{{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}}==
<syntaxhighlight lang="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
delay 1.5
set end of table to lookupVendor(burger)
end repeat
set text item delimiters to linefeed
return table as string
</syntaxhighlight>
If this is part of a larger script you probably want to save and restore the text item delimiters:
<syntaxhighlight 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</syntaxhighlight>
{{out}}
<pre>
Intel Corporate
Apple, Inc.
Line 94 ⟶ 146:
PEGATRON CORPORATION
Dell Inc.
</pre>
=={{header|Arturo}}==
<
print [mac "=>" read ~"http://api.macvendors.com/|mac|"]
pause 1500
]</
{{out}}
Line 111 ⟶ 162:
=={{header|AutoHotkey}}==
<
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("GET", "http://api.macvendors.com/" MAC)
WebRequest.Send()
return WebRequest.ResponseText
}</
Examples:<
Outputs:<pre>Dell Inc.</pre>
=={{header|BaCon}}==
This code requires BaCon 3.8.2 or higher.
<
website$ = "api.macvendors.com"
Line 132 ⟶ 183:
CLOSE NETWORK mynet
PRINT TOKEN$(info$, 2, "\r\n\r\n")</
{{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">
#include <curl/curl.h>
#include <string.h>
Line 216 ⟶ 307:
return EXIT_FAILURE;
}
</syntaxhighlight>
Invocation and output :
<pre>
Line 227 ⟶ 318:
=={{header|C sharp|C#}}==
<
using System.Net;
using System.Net.Http;
Line 246 ⟶ 337:
Console.ReadLine();
}
}</
{{out}}
Line 258 ⟶ 349:
=={{header|C++}}==
{{libheader|Boost}}
<
// the Boost documentation.
Line 320 ⟶ 411:
}
return EXIT_FAILURE;
}</
{{out}}
Line 329 ⟶ 420:
=={{header|Common Lisp}}==
<
(defun mac-vendor (mac)
Line 338 ⟶ 429:
(format t "~%Vendor is ~a" vendor)
(error "~%Not a MAC address: ~a" mac))))
</syntaxhighlight>
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{libheader| IdHttp}}
<syntaxhighlight lang="delphi">
program MAC_Vendor_Lookup;
Line 374 ⟶ 465:
Writeln(macLookUp('BC:5F:F4'));
readln;
end.</
{{out}}
<pre>Samsung Electronics Co.,Ltd
Line 381 ⟶ 472:
=={{header|Factor}}==
<
sequences threads ;
Line 391 ⟶ 482:
"FC:FB:FB:01:FA:21"
"10-11-22-33-44-55-66"
[ mac-vendor print 1 seconds sleep ] tri@</
{{out}}
<pre>
Line 400 ⟶ 491:
=={{header|FreeBASIC}}==
<
Var f = Freefile
Dim As String tmp
Line 425 ⟶ 516:
Next i
Sleep
</syntaxhighlight>
{{out}}
<pre>
Line 435 ⟶ 526:
=={{header|Free Pascal}}==
<
uses
Line 458 ⟶ 549:
end;
end;
end.</
{{out}}
Line 470 ⟶ 561:
=={{header|Go}}==
<
import (
Line 490 ⟶ 581:
fmt.Println(macLookUp("BC:5F:F4"))
}
</syntaxhighlight>
{{Out}}
<pre>Samsung Electronics Co.,Ltd
Line 501 ⟶ 592:
{{libheader|http-client}}
<
{- stack
script
Line 547 ⟶ 638:
putStr $ printf "%-17s" mac ++ " = "
vendor <- lookupMac mgr mac
putStrLn vendor</
{{Out}}
Line 560 ⟶ 651:
=={{header|J}}==
'''Solution
<
lookupMACvendor=: [: gethttp 'http://api.macvendors.com/'&,</
'''Example Usage
<
(,&' ' , 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</
=={{header|Java}}==
<
import java.io.BufferedReader;
Line 618 ⟶ 709:
}
}
}</
===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}}==
<
var mac = "88:53:2E:67:07:BE";
function findmac(){
Line 628 ⟶ 775:
findmac();
</syntaxhighlight>
{{out}}
<pre>Intel Corporate</pre>
=={{header|Julia}}==
<
using Requests
Line 647 ⟶ 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</
{{out}}
Line 656 ⟶ 803:
=={{header|Kotlin}}==
<
import java.net.URL
Line 665 ⟶ 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))
}</
{{out}}
Line 674 ⟶ 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}}==
<
-- Created by James A. Donnell Jr.
-- www.JamesDonnell.com
Line 689 ⟶ 860:
local macAddress = "FC-A1-3E-2A-1C-33"
print(lookup(macAddress))</
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
Module Checkit {
httpGet$=lambda$ (url$, timeout=500)->{
Line 709 ⟶ 880:
declare htmldoc nothing
}
Urls=("88:53:2E:67:07:BE", "FC:FB:FB:01:FA:21", "D4:F4:6F:C9:EF:8D", "
url=each(URLs)
While Url {
Print Array$(URL),@(20), httpGet$("
Wait
}
}
Checkit
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
Examples:<
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}}==
<
for mac in ["FC-A1-3E", "FC:FB:FB:01:FA:21", "BC:5F:F4"]:
echo newHttpClient().getContent("http://api.macvendors.com/"&mac)</
{{out}}
Line 736 ⟶ 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">
(* build with ocamlfind ocamlopt -package netclient -linkpkg macaddr.ml -o macaddr *)
Line 773 ⟶ 1,008:
</syntaxhighlight>
{{out}}
<pre>
Line 785 ⟶ 1,020:
=={{header|Perl}}==
<
use
use warnings;
use LWP;
use Time::HiRes qw(sleep);
our $VERSION = 1.000_000;
Line 794 ⟶ 1,030:
my $ua = LWP::UserAgent->new;
no warnings 'qw';
my @macs = qw(
FC-A1-3EFC:FB:FB:01:FA:21 00,0d,4b
23:45:67 FC:FB:FB:01:FA:21
BC:5F:F4
);
my $vendor = get_mac_vendor($mac);
if ($vendor) {
say "$mac = $vendor";
}
sleep 1.5 if @macs;
}
Line 850 ⟶ 1,088:
# }
# return;
#}</
{{out}}
Line 865 ⟶ 1,103:
=={{header|Phix}}==
{{libheader|Phix/libcurl}}
<!--<
<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 886 ⟶ 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>
<!--</
{{out}}
<pre>
Line 892 ⟶ 1,130:
</pre>
=={{header|
{{trans|AppleScript}}
<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();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
foreach ($macList as $burger) {
curl_setopt($curl, CURLOPT_URL, "$apiRoot/$burger");
echo(curl_exec($curl));
echo("\n");
sleep(2);
}
curl_close($curl);
?></syntaxhighlight>
{{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}}==
<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)</
{{out}}
<pre>88:53:2E:67:07:BE Intel Corporate
Line 922 ⟶ 1,191:
=={{header|Racket}}==
<
(require net/url)
Line 935 ⟶ 1,204:
"FC:FB:FB:01:FA:21"
"D4:F4:6F:C9:EF:8D"))))
(printf "~a\t~a~%" i (lookup-MAC-address i))))</
{{out}}
Line 947 ⟶ 1,216:
Apparently there is some rate limiting on place now, sleep a bit between requests.
<syntaxhighlight lang="raku"
my $ua = HTTP::UserAgent.new;
Line 971 ⟶ 1,240:
00:0d:4b
23:45:67
> -> $mac { say lookup $mac }</
{{out}}
<pre>ASRock Incorporation
Line 981 ⟶ 1,250:
=={{header|Red}}==
<
</syntaxhighlight>
{{out}}
<pre>MAC address: 88:53:2E:67:07:BE
Line 989 ⟶ 1,258:
=={{header|REXX}}==
This REXX version only works under Microsoft Windows and Regina REXX.
<
win_command = 'getmac' /*name of the Microsoft Windows command*/
win_command_options = '/v /fo list' /*options of " " " */
Line 1,014 ⟶ 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. */</
{{out|output|text= when using the default input:}}
<pre>
Line 1,021 ⟶ 1,290:
=={{header|Ring}}==
<
# Project: MAC Vendor Lookup
Line 1,033 ⟶ 1,302:
url = download("api.macvendors.com/" + mac)
see url + nl
</syntaxhighlight>
Output:
<pre>
Line 1,043 ⟶ 1,312:
=={{header|Ruby}}==
<
arr = ['88:53:2E:67:07:BE', 'FC:FB:FB:01:FA:21', 'D4:F4:6F:C9:EF:8D', '23:45:67']
Line 1,050 ⟶ 1,319:
vendor = Net::HTTP.get('api.macvendors.com', "/#{addr}/") rescue nil
puts "#{addr} #{vendor}"
end</
{{out}}
<pre>88:53:2E:67:07:BE Intel Corporate
Line 1,059 ⟶ 1,328:
=={{header|Rust}}==
<
use std::{thread, time};
Line 1,110 ⟶ 1,379:
}
}
</syntaxhighlight>
Output:
<pre>
Line 1,120 ⟶ 1,389:
=={{header|Scala}}==
<
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,127 ⟶ 1,396:
macs.foreach(mac => println(lookupVendor(mac)))
}</
=={{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}}==
<
# finally is a bit like go's defer
Line 1,149 ⟶ 1,443:
foreach mac {00-14-22-01-23-45 88:53:2E:67:07:BE} {
puts "$mac\t[maclookup $mac]"
}</
{{out}}
Line 1,157 ⟶ 1,451:
=={{header|UNIX Shell}}==
{{trans|AppleScript}}
{{works with|Bourne Again SHell}}
{{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>
{{out}}
All the above versions have identical output:
<pre>
Intel Corporate
Line 1,173 ⟶ 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,185 ⟶ 1,523:
wscript.echo mac & " -> " & WebRequest.ResponseText
next
</syntaxhighlight>
Output:
<pre>
Line 1,191 ⟶ 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,197 ⟶ 1,600:
However, if Wren is embedded in (say) a suitable Go program, then we can ask the latter to do it for us.
<
class MAC {
foreign static lookup(address)
Line 1,204 ⟶ 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"))</
which we embed in the following Go program and run it.
{{libheader|WrenGo}}
<
package main
Line 1,238 ⟶ 1,641:
func main() {
vm := wren.NewVM()
fileName := "
methodMap := wren.MethodMap{"static lookup(_)": macLookup}
classMap := wren.ClassMap{"MAC": wren.NewClass(nil, nil, methodMap)}
Line 1,245 ⟶ 1,648:
vm.InterpretFile(fileName)
vm.Free()
}</
{{out}}
Line 1,256 ⟶ 1,659:
{{trans|Lua}}
Uses libcurl (the multiprotocol file transfer library) to do the web query
<
const MAC_VENDORS="http://api.macvendors.com/";
Line 1,264 ⟶ 1,667:
vender=vender[0].del(0,vender[1]); // remove HTTP header
vender.text; // Data --> String (Data is a byte bucket)
}</
<
lookUp("4c:72:b9:56:fe:bc").println();
lookUp("foobar").println();</
{{out}}
<pre>
Line 1,276 ⟶ 1,679:
=={{header|Zoea}}==
<syntaxhighlight lang="zoea">
program: mac_vendor_lookup
Line 1,284 ⟶ 1,687:
derive: 'http://api.macvendors.com/D4:F4:6F:C9:EF:8D'
output: 'Apple, Inc.'
</syntaxhighlight>
=={{header|Zoea Visual}}==
[http://zoea.co.uk/examples/zv-rc/MAC_vendor_lookup.png MAC Vendor Lookup]
{{omit from|EasyLang|Has no internet functions}}
|