MAC vendor lookup: Difference between revisions
Content added Content deleted
mNo edit summary |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 19: | Line 19: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{libheader|AWS}} |
{{libheader|AWS}} |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_IO; |
||
with AWS.Client; |
with AWS.Client; |
||
Line 52: | Line 52: | ||
Lookup ("23-45-67"); delay 1.500; |
Lookup ("23-45-67"); delay 1.500; |
||
Lookup ("foobar"); |
Lookup ("foobar"); |
||
end MAC_Vendor;</ |
end MAC_Vendor;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>88:53:2E:67:07:BE Intel Corporate |
<pre>88:53:2E:67:07:BE Intel Corporate |
||
Line 68: | 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. |
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 |
]load HttpCommand |
||
Line 100: | Line 100: | ||
⍝ the result is an array (a 1-row by N-column matrix). to print out one vendor |
⍝ 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. |
⍝ per line, we reshape it to be N rows by 1 column instead. |
||
{(1⌷⍴⍵) 1 ⍴ ⍵} vendorList</ |
{(1⌷⍴⍵) 1 ⍴ ⍵} vendorList</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
Line 112: | Line 112: | ||
=={{header|AppleScript}}== |
=={{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", ¬ |
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"} |
"FC:FB:FB:01:FA:21", "4c:72:b9:56:fe:bc", "00-14-22-01-23-45"} |
||
Line 129: | Line 129: | ||
set text item delimiters to linefeed |
set text item delimiters to linefeed |
||
return table as string |
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: |
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 text item delimiters to linefeed |
||
set tableText to table as string |
set tableText to table as string |
||
set text item delimiters to savedTID |
set text item delimiters to savedTID |
||
return tableText</ |
return tableText</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 150: | Line 150: | ||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">loop ["FC-A1-3E" "FC:FB:FB:01:FA:21" "BC:5F:F4"] 'mac [ |
||
print [mac "=>" read ~"http://api.macvendors.com/|mac|"] |
print [mac "=>" read ~"http://api.macvendors.com/|mac|"] |
||
pause 1500 |
pause 1500 |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 162: | Line 162: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
< |
<syntaxhighlight lang="autohotkey">macLookup(MAC){ |
||
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1") |
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1") |
||
WebRequest.Open("GET", "http://api.macvendors.com/" MAC) |
WebRequest.Open("GET", "http://api.macvendors.com/" MAC) |
||
WebRequest.Send() |
WebRequest.Send() |
||
return WebRequest.ResponseText |
return WebRequest.ResponseText |
||
}</ |
}</syntaxhighlight> |
||
Examples:< |
Examples:<syntaxhighlight lang="autohotkey">MsgBox % macLookup("00-14-22-01-23-45")</syntaxhighlight> |
||
Outputs:<pre>Dell Inc.</pre> |
Outputs:<pre>Dell Inc.</pre> |
||
=={{header|BaCon}}== |
=={{header|BaCon}}== |
||
This code requires BaCon 3.8.2 or higher. |
This code requires BaCon 3.8.2 or higher. |
||
< |
<syntaxhighlight lang="bacon">OPTION TLS TRUE |
||
website$ = "api.macvendors.com" |
website$ = "api.macvendors.com" |
||
Line 183: | Line 183: | ||
CLOSE NETWORK mynet |
CLOSE NETWORK mynet |
||
PRINT TOKEN$(info$, 2, "\r\n\r\n")</ |
PRINT TOKEN$(info$, 2, "\r\n\r\n")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Hon Hai Precision Ind. Co.,Ltd.</pre> |
<pre>Hon Hai Precision Ind. Co.,Ltd.</pre> |
||
Line 189: | Line 189: | ||
=={{header|C}}== |
=={{header|C}}== |
||
Takes MAC address as input, prints usage on incorrect invocation, requires [https://curl.haxx.se/libcurl/ libcurl] |
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 <curl/curl.h> |
||
#include <string.h> |
#include <string.h> |
||
Line 267: | Line 267: | ||
return EXIT_FAILURE; |
return EXIT_FAILURE; |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Invocation and output : |
Invocation and output : |
||
<pre> |
<pre> |
||
Line 278: | Line 278: | ||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
< |
<syntaxhighlight lang="csharp">using System; |
||
using System.Net; |
using System.Net; |
||
using System.Net.Http; |
using System.Net.Http; |
||
Line 297: | Line 297: | ||
Console.ReadLine(); |
Console.ReadLine(); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 309: | Line 309: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{libheader|Boost}} |
{{libheader|Boost}} |
||
< |
<syntaxhighlight lang="cpp">// This code is based on the example 'Simple HTTP Client' included with |
||
// the Boost documentation. |
// the Boost documentation. |
||
Line 371: | Line 371: | ||
} |
} |
||
return EXIT_FAILURE; |
return EXIT_FAILURE; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 380: | Line 380: | ||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
< |
<syntaxhighlight lang="common lisp">(quicklisp:quickload :Drakma) ; or load it in another way |
||
(defun mac-vendor (mac) |
(defun mac-vendor (mac) |
||
Line 389: | Line 389: | ||
(format t "~%Vendor is ~a" vendor) |
(format t "~%Vendor is ~a" vendor) |
||
(error "~%Not a MAC address: ~a" mac)))) |
(error "~%Not a MAC address: ~a" mac)))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
{{libheader| System.SysUtils}} |
{{libheader| System.SysUtils}} |
||
{{libheader| IdHttp}} |
{{libheader| IdHttp}} |
||
<syntaxhighlight lang="delphi"> |
|||
<lang Delphi> |
|||
program MAC_Vendor_Lookup; |
program MAC_Vendor_Lookup; |
||
Line 425: | Line 425: | ||
Writeln(macLookUp('BC:5F:F4')); |
Writeln(macLookUp('BC:5F:F4')); |
||
readln; |
readln; |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Samsung Electronics Co.,Ltd |
<pre>Samsung Electronics Co.,Ltd |
||
Line 432: | Line 432: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">USING: accessors calendar continuations http.client io kernel |
||
sequences threads ; |
sequences threads ; |
||
Line 442: | Line 442: | ||
"FC:FB:FB:01:FA:21" |
"FC:FB:FB:01:FA:21" |
||
"10-11-22-33-44-55-66" |
"10-11-22-33-44-55-66" |
||
[ mac-vendor print 1 seconds sleep ] tri@</ |
[ mac-vendor print 1 seconds sleep ] tri@</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 451: | Line 451: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic">Function pipeout(Byval s As String = "") Byref As String |
||
Var f = Freefile |
Var f = Freefile |
||
Dim As String tmp |
Dim As String tmp |
||
Line 476: | Line 476: | ||
Next i |
Next i |
||
Sleep |
Sleep |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 486: | Line 486: | ||
=={{header|Free Pascal}}== |
=={{header|Free Pascal}}== |
||
< |
<syntaxhighlight lang="pascal">program MACVendorLookup; |
||
uses |
uses |
||
Line 509: | Line 509: | ||
end; |
end; |
||
end; |
end; |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 521: | Line 521: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 541: | Line 541: | ||
fmt.Println(macLookUp("BC:5F:F4")) |
fmt.Println(macLookUp("BC:5F:F4")) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre>Samsung Electronics Co.,Ltd |
<pre>Samsung Electronics Co.,Ltd |
||
Line 552: | Line 552: | ||
{{libheader|http-client}} |
{{libheader|http-client}} |
||
< |
<syntaxhighlight lang="haskell">#!/usr/bin/env stack |
||
{- stack |
{- stack |
||
script |
script |
||
Line 598: | Line 598: | ||
putStr $ printf "%-17s" mac ++ " = " |
putStr $ printf "%-17s" mac ++ " = " |
||
vendor <- lookupMac mgr mac |
vendor <- lookupMac mgr mac |
||
putStrLn vendor</ |
putStrLn vendor</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
Line 611: | Line 611: | ||
=={{header|J}}== |
=={{header|J}}== |
||
'''Solution |
'''Solution |
||
< |
<syntaxhighlight lang="j">require 'web/gethttp' |
||
lookupMACvendor=: [: gethttp 'http://api.macvendors.com/'&,</ |
lookupMACvendor=: [: gethttp 'http://api.macvendors.com/'&,</syntaxhighlight> |
||
'''Example Usage |
'''Example Usage |
||
< |
<syntaxhighlight 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 |
(,&' ' , lookupMACvendor)&> addr |
||
88:53:2E:67:07:BE Intel Corporate |
88:53:2E:67:07:BE Intel Corporate |
||
FC:FB:FB:01:FA:21 Cisco Systems, Inc |
FC:FB:FB:01:FA:21 Cisco Systems, Inc |
||
D4:F4:6F:C9:EF:8D Apple, Inc. |
D4:F4:6F:C9:EF:8D Apple, Inc. |
||
23:45:67 Vendor not found</ |
23:45:67 Vendor not found</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java">package com.jamesdonnell.MACVendor; |
||
import java.io.BufferedReader; |
import java.io.BufferedReader; |
||
Line 669: | Line 669: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Javascript}}== |
=={{header|Javascript}}== |
||
< |
<syntaxhighlight lang="javascript"> |
||
var mac = "88:53:2E:67:07:BE"; |
var mac = "88:53:2E:67:07:BE"; |
||
function findmac(){ |
function findmac(){ |
||
Line 679: | Line 679: | ||
findmac(); |
findmac(); |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>Intel Corporate</pre> |
<pre>Intel Corporate</pre> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia"># v0.6.0 |
||
using Requests |
using Requests |
||
Line 698: | Line 698: | ||
for addr in ["88:53:2E:67:07:BE", "FC:FB:FB:01:FA:21", "D4:F4:6F:C9:EF:8D", "23:45:67"] |
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)) |
println("$addr -> ", getvendor(addr)) |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 707: | Line 707: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
< |
<syntaxhighlight lang="scala">// version 1.1.2 |
||
import java.net.URL |
import java.net.URL |
||
Line 716: | Line 716: | ||
val macs = arrayOf("FC-A1-3E", "FC:FB:FB:01:FA:21", "88:53:2E:67:07:BE", "D4:F4:6F:C9:EF:8D") |
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)) |
for (mac in macs) println(lookupVendor(mac)) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 728: | Line 728: | ||
=={{header|Logo}}== |
=={{header|Logo}}== |
||
{{works with|UCB 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 |
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] |
4c:72:b9:56:fe:bc 00-14-22-01-23-45] |
||
Line 742: | Line 742: | ||
] |
] |
||
bye |
bye |
||
bye</ |
bye</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>Intel Corporate |
<pre>Intel Corporate |
||
Line 751: | Line 751: | ||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
< |
<syntaxhighlight lang="lua">-- Requires LuaSocket extension by Lua |
||
-- Created by James A. Donnell Jr. |
-- Created by James A. Donnell Jr. |
||
-- www.JamesDonnell.com |
-- www.JamesDonnell.com |
||
Line 764: | Line 764: | ||
local macAddress = "FC-A1-3E-2A-1C-33" |
local macAddress = "FC-A1-3E-2A-1C-33" |
||
print(lookup(macAddress))</ |
print(lookup(macAddress))</syntaxhighlight> |
||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
<syntaxhighlight lang="m2000 interpreter"> |
|||
<lang M2000 Interpreter> |
|||
Module Checkit { |
Module Checkit { |
||
httpGet$=lambda$ (url$, timeout=500)->{ |
httpGet$=lambda$ (url$, timeout=500)->{ |
||
Line 792: | Line 792: | ||
} |
} |
||
Checkit |
Checkit |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">macLookup[mac_String] := Quiet[Check[Import["http://api.macvendors.com/" <> mac], "N/A"]]</syntaxhighlight> |
||
Examples:< |
Examples:<syntaxhighlight lang="mathematica">macLookup["00-14-22-01-23-45"]</syntaxhighlight> |
||
Outputs:<pre>Dell Inc.</pre> |
Outputs:<pre>Dell Inc.</pre> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import httpclient |
||
for mac in ["FC-A1-3E", "FC:FB:FB:01:FA:21", "BC:5F:F4"]: |
for mac in ["FC-A1-3E", "FC:FB:FB:01:FA:21", "BC:5F:F4"]: |
||
echo newHttpClient().getContent("http://api.macvendors.com/"&mac)</ |
echo newHttpClient().getContent("http://api.macvendors.com/"&mac)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 812: | Line 812: | ||
</pre> |
</pre> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
<syntaxhighlight lang="ocaml"> |
|||
<lang OCaml> |
|||
(* build with ocamlfind ocamlopt -package netclient -linkpkg macaddr.ml -o macaddr *) |
(* build with ocamlfind ocamlopt -package netclient -linkpkg macaddr.ml -o macaddr *) |
||
Line 848: | Line 848: | ||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 860: | Line 860: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">#!/usr/bin/env perl -T |
||
use v5.18.2; |
use v5.18.2; |
||
use warnings; |
use warnings; |
||
Line 928: | Line 928: | ||
# } |
# } |
||
# return; |
# return; |
||
#}</ |
#}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 943: | Line 943: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{libheader|Phix/libcurl}} |
{{libheader|Phix/libcurl}} |
||
<!--< |
<!--<syntaxhighlight lang="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: #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 |
<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 964: | Line 964: | ||
<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_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> |
<span style="color: #7060A8;">curl_global_cleanup</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 972: | Line 972: | ||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
{{trans|AppleScript}} |
{{trans|AppleScript}} |
||
< |
<syntaxhighlight lang="php"><?php |
||
$apiRoot = "https://api.macvendors.com"; |
$apiRoot = "https://api.macvendors.com"; |
||
$macList = array("88:53:2E:67:07:BE", "D4:F4:6F:C9:EF:8D", |
$macList = array("88:53:2E:67:07:BE", "D4:F4:6F:C9:EF:8D", |
||
Line 986: | Line 986: | ||
} |
} |
||
curl_close($curl); |
curl_close($curl); |
||
?></ |
?></syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
Line 997: | Line 997: | ||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
{{trans|AppleScript}} |
{{trans|AppleScript}} |
||
< |
<syntaxhighlight lang="powershell">$apiRoot = "http://api.macvendors.com" |
||
$macAddresses = @("88:53:2E:67:07:BE", "D4:F4:6F:C9:EF:8D", |
$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", |
"FC:FB:FB:01:FA:21", "4c:72:b9:56:fe:bc", |
||
Line 1,005: | Line 1,005: | ||
(Invoke-WebRequest "$apiRoot/$_").Content |
(Invoke-WebRequest "$apiRoot/$_").Content |
||
Start-Sleep 1.5 |
Start-Sleep 1.5 |
||
}</ |
}</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
Line 1,017: | Line 1,017: | ||
{{libheader|requests}} |
{{libheader|requests}} |
||
< |
<syntaxhighlight lang="python">import requests |
||
for addr in ['88:53:2E:67:07:BE', 'FC:FB:FB:01:FA:21', |
for addr in ['88:53:2E:67:07:BE', 'FC:FB:FB:01:FA:21', |
||
'D4:F4:6F:C9:EF:8D', '23:45:67']: |
'D4:F4:6F:C9:EF:8D', '23:45:67']: |
||
vendor = requests.get('http://api.macvendors.com/' + addr).text |
vendor = requests.get('http://api.macvendors.com/' + addr).text |
||
print(addr, vendor)</ |
print(addr, vendor)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>88:53:2E:67:07:BE Intel Corporate |
<pre>88:53:2E:67:07:BE Intel Corporate |
||
Line 1,031: | Line 1,031: | ||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket">#lang racket |
||
(require net/url) |
(require net/url) |
||
Line 1,044: | Line 1,044: | ||
"FC:FB:FB:01:FA:21" |
"FC:FB:FB:01:FA:21" |
||
"D4:F4:6F:C9:EF:8D")))) |
"D4:F4:6F:C9:EF:8D")))) |
||
(printf "~a\t~a~%" i (lookup-MAC-address i))))</ |
(printf "~a\t~a~%" i (lookup-MAC-address i))))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,056: | Line 1,056: | ||
Apparently there is some rate limiting on place now, sleep a bit between requests. |
Apparently there is some rate limiting on place now, sleep a bit between requests. |
||
<lang |
<syntaxhighlight lang="raku" line>use HTTP::UserAgent; |
||
my $ua = HTTP::UserAgent.new; |
my $ua = HTTP::UserAgent.new; |
||
Line 1,080: | Line 1,080: | ||
00:0d:4b |
00:0d:4b |
||
23:45:67 |
23:45:67 |
||
> -> $mac { say lookup $mac }</ |
> -> $mac { say lookup $mac }</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>ASRock Incorporation |
<pre>ASRock Incorporation |
||
Line 1,090: | Line 1,090: | ||
=={{header|Red}}== |
=={{header|Red}}== |
||
< |
<syntaxhighlight lang="red">print read rejoin [http://api.macvendors.com/ ask "MAC address: "] |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>MAC address: 88:53:2E:67:07:BE |
<pre>MAC address: 88:53:2E:67:07:BE |
||
Line 1,098: | Line 1,098: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
This REXX version only works under Microsoft Windows and Regina REXX. |
This REXX version only works under Microsoft Windows and Regina REXX. |
||
< |
<syntaxhighlight 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 = 'getmac' /*name of the Microsoft Windows command*/ |
||
win_command_options = '/v /fo list' /*options of " " " */ |
win_command_options = '/v /fo list' /*options of " " " */ |
||
Line 1,123: | Line 1,123: | ||
if maker=. | MACaddr==. then say 'MAC address manufacturer not found.' |
if maker=. | MACaddr==. then say 'MAC address manufacturer not found.' |
||
else say 'manufacturer for MAC address ' MACaddr " is " maker |
else say 'manufacturer for MAC address ' MACaddr " is " maker |
||
exit 0 /*stick a fork in it, we're all done. */</ |
exit 0 /*stick a fork in it, we're all done. */</syntaxhighlight> |
||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre> |
<pre> |
||
Line 1,130: | Line 1,130: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
# Project: MAC Vendor Lookup |
# Project: MAC Vendor Lookup |
||
Line 1,142: | Line 1,142: | ||
url = download("api.macvendors.com/" + mac) |
url = download("api.macvendors.com/" + mac) |
||
see url + nl |
see url + nl |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 1,152: | Line 1,152: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight 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'] |
arr = ['88:53:2E:67:07:BE', 'FC:FB:FB:01:FA:21', 'D4:F4:6F:C9:EF:8D', '23:45:67'] |
||
Line 1,159: | Line 1,159: | ||
vendor = Net::HTTP.get('api.macvendors.com', "/#{addr}/") rescue nil |
vendor = Net::HTTP.get('api.macvendors.com', "/#{addr}/") rescue nil |
||
puts "#{addr} #{vendor}" |
puts "#{addr} #{vendor}" |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>88:53:2E:67:07:BE Intel Corporate |
<pre>88:53:2E:67:07:BE Intel Corporate |
||
Line 1,168: | Line 1,168: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<syntaxhighlight lang="rust">extern crate reqwest; |
||
use std::{thread, time}; |
use std::{thread, time}; |
||
Line 1,219: | Line 1,219: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 1,229: | Line 1,229: | ||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
< |
<syntaxhighlight 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") |
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,236: | Line 1,236: | ||
macs.foreach(mac => println(lookupVendor(mac))) |
macs.foreach(mac => println(lookupVendor(mac))) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
Line 1,242: | Line 1,242: | ||
{{works with|Chicken Scheme}} |
{{works with|Chicken Scheme}} |
||
{{libheader|http-client}} |
{{libheader|http-client}} |
||
< |
<syntaxhighlight lang="scheme">(import http-client (chicken io)) |
||
(define api-root "http://api.macvendors.com") |
(define api-root "http://api.macvendors.com") |
||
(define mac-addresses '("88:53:2E:67:07:BE" "D4:F4:6F:C9:EF:8D" |
(define mac-addresses '("88:53:2E:67:07:BE" "D4:F4:6F:C9:EF:8D" |
||
Line 1,255: | Line 1,255: | ||
(newline) |
(newline) |
||
(map (lambda (burger) (sleep 2) (display (get-vendor burger)) (newline)) |
(map (lambda (burger) (sleep 2) (display (get-vendor burger)) (newline)) |
||
(cdr mac-addresses))</ |
(cdr mac-addresses))</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>Intel Corporate |
<pre>Intel Corporate |
||
Line 1,264: | Line 1,264: | ||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
< |
<syntaxhighlight lang="tcl">package require http |
||
# finally is a bit like go's defer |
# finally is a bit like go's defer |
||
Line 1,283: | Line 1,283: | ||
foreach mac {00-14-22-01-23-45 88:53:2E:67:07:BE} { |
foreach mac {00-14-22-01-23-45 88:53:2E:67:07:BE} { |
||
puts "$mac\t[maclookup $mac]" |
puts "$mac\t[maclookup $mac]" |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,295: | Line 1,295: | ||
{{works with|Z Shell}} |
{{works with|Z Shell}} |
||
Surprising that nobody had implemented the Bash / Shell version yet. |
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) |
4c:72:b9:56:fe:bc 00-14-22-01-23-45) |
||
Line 1,306: | Line 1,306: | ||
sleep 2 |
sleep 2 |
||
lookup "$burger" |
lookup "$burger" |
||
done</ |
done</syntaxhighlight> |
||
It can be made to work in a pure-POSIX shell without array variables: |
It can be made to work in a pure-POSIX shell without array variables: |
||
{{works with|Bourne Shell}} |
{{works with|Bourne Shell}} |
||
{{works with|Almquist 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 |
4c:72:b9:56:fe:bc 00-14-22-01-23-45 |
||
Line 1,323: | Line 1,323: | ||
sleep 2 |
sleep 2 |
||
curl -s "http://api.macvendors.com/$burger" && echo |
curl -s "http://api.macvendors.com/$burger" && echo |
||
done</ |
done</syntaxhighlight> |
||
And hey, just for completeness, let's toss in a [t]csh version: |
And hey, just for completeness, let's toss in a [t]csh version: |
||
{{works with|C Shell}} |
{{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) |
4c:72:b9:56:fe:bc 00-14-22-01-23-45) |
||
Line 1,337: | Line 1,337: | ||
sleep 2 |
sleep 2 |
||
lookup "$burger" |
lookup "$burger" |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,351: | Line 1,351: | ||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
<lang> |
<syntaxhighlight lang="text"> |
||
a=array("00-20-6b-ba-d0-cb","00-40-ae-04-87-86") |
a=array("00-20-6b-ba-d0-cb","00-40-ae-04-87-86") |
||
set WebRequest = CreateObject("WinHttp.WinHttpRequest.5.1") |
set WebRequest = CreateObject("WinHttp.WinHttpRequest.5.1") |
||
Line 1,363: | Line 1,363: | ||
wscript.echo mac & " -> " & WebRequest.ResponseText |
wscript.echo mac & " -> " & WebRequest.ResponseText |
||
next |
next |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 1,372: | Line 1,372: | ||
=={{header|Vlang}}== |
=={{header|Vlang}}== |
||
< |
<syntaxhighlight lang="vlang">import net.http |
||
import time |
import time |
||
Line 1,394: | Line 1,394: | ||
resp := http.get("http://api.macvendors.com/" + mac) or {println('No data from server') return ''} |
resp := http.get("http://api.macvendors.com/" + mac) or {println('No data from server') return ''} |
||
return resp.body.str() |
return resp.body.str() |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,407: | Line 1,407: | ||
However, if Wren is embedded in (say) a suitable Go program, then we can ask the latter to do it for us. |
However, if Wren is embedded in (say) a suitable Go program, then we can ask the latter to do it for us. |
||
< |
<syntaxhighlight lang="ecmascript">/* mac_vendor_lookup.wren */ |
||
class MAC { |
class MAC { |
||
foreign static lookup(address) |
foreign static lookup(address) |
||
Line 1,414: | Line 1,414: | ||
System.print(MAC.lookup("FC:FB:FB:01:FA:21")) |
System.print(MAC.lookup("FC:FB:FB:01:FA:21")) |
||
for (i in 1..1e8) {} // slow down request |
for (i in 1..1e8) {} // slow down request |
||
System.print(MAC.lookup("23:45:67"))</ |
System.print(MAC.lookup("23:45:67"))</syntaxhighlight> |
||
which we embed in the following Go program and run it. |
which we embed in the following Go program and run it. |
||
{{libheader|WrenGo}} |
{{libheader|WrenGo}} |
||
< |
<syntaxhighlight lang="go">/* mac_vendor_lookup.go */ |
||
package main |
package main |
||
Line 1,455: | Line 1,455: | ||
vm.InterpretFile(fileName) |
vm.InterpretFile(fileName) |
||
vm.Free() |
vm.Free() |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,466: | Line 1,466: | ||
{{trans|Lua}} |
{{trans|Lua}} |
||
Uses libcurl (the multiprotocol file transfer library) to do the web query |
Uses libcurl (the multiprotocol file transfer library) to do the web query |
||
< |
<syntaxhighlight lang="zkl">var [const] CURL=Import("zklCurl"); // libcurl |
||
const MAC_VENDORS="http://api.macvendors.com/"; |
const MAC_VENDORS="http://api.macvendors.com/"; |
||
Line 1,474: | Line 1,474: | ||
vender=vender[0].del(0,vender[1]); // remove HTTP header |
vender=vender[0].del(0,vender[1]); // remove HTTP header |
||
vender.text; // Data --> String (Data is a byte bucket) |
vender.text; // Data --> String (Data is a byte bucket) |
||
}</ |
}</syntaxhighlight> |
||
< |
<syntaxhighlight lang="zkl">lookUp("FC-A1-3E-2A-1C-33").println(); |
||
lookUp("4c:72:b9:56:fe:bc").println(); |
lookUp("4c:72:b9:56:fe:bc").println(); |
||
lookUp("foobar").println();</ |
lookUp("foobar").println();</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,486: | Line 1,486: | ||
=={{header|Zoea}}== |
=={{header|Zoea}}== |
||
<syntaxhighlight lang="zoea"> |
|||
<lang Zoea> |
|||
program: mac_vendor_lookup |
program: mac_vendor_lookup |
||
Line 1,494: | Line 1,494: | ||
derive: 'http://api.macvendors.com/D4:F4:6F:C9:EF:8D' |
derive: 'http://api.macvendors.com/D4:F4:6F:C9:EF:8D' |
||
output: 'Apple, Inc.' |
output: 'Apple, Inc.' |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Zoea Visual}}== |
=={{header|Zoea Visual}}== |