MAC vendor lookup: Difference between revisions

m
syntax highlighting fixup automation
mNo edit summary
m (syntax highlighting fixup automation)
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 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.
{(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"}
Line 129:
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 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 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 183:
CLOSE NETWORK mynet
 
PRINT TOKEN$(info$, 2, "\r\n\r\n")</langsyntaxhighlight>
{{out}}
<pre>Hon Hai Precision Ind. Co.,Ltd.</pre>
Line 189:
=={{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 267:
return EXIT_FAILURE;
}
</syntaxhighlight>
</lang>
Invocation and output :
<pre>
Line 278:
=={{header|C sharp|C#}}==
 
<langsyntaxhighlight lang="csharp">using System;
using System.Net;
using System.Net.Http;
Line 297:
Console.ReadLine();
}
}</langsyntaxhighlight>
 
{{out}}
Line 309:
=={{header|C++}}==
{{libheader|Boost}}
<langsyntaxhighlight lang="cpp">// This code is based on the example 'Simple HTTP Client' included with
// the Boost documentation.
 
Line 371:
}
return EXIT_FAILURE;
}</langsyntaxhighlight>
 
{{out}}
Line 380:
 
=={{header|Common Lisp}}==
<langsyntaxhighlight Commonlang="common Lisplisp">(quicklisp:quickload :Drakma) ; or load it in another way
 
(defun mac-vendor (mac)
Line 389:
(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 425:
Writeln(macLookUp('BC:5F:F4'));
readln;
end.</langsyntaxhighlight>
{{out}}
<pre>Samsung Electronics Co.,Ltd
Line 432:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: accessors calendar continuations http.client io kernel
sequences threads ;
 
Line 442:
"FC:FB:FB:01:FA:21"
"10-11-22-33-44-55-66"
[ mac-vendor print 1 seconds sleep ] tri@</langsyntaxhighlight>
{{out}}
<pre>
Line 451:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">Function pipeout(Byval s As String = "") Byref As String
Var f = Freefile
Dim As String tmp
Line 476:
Next i
Sleep
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 486:
 
=={{header|Free Pascal}}==
<langsyntaxhighlight lang="pascal">program MACVendorLookup;
 
uses
Line 509:
end;
end;
end.</langsyntaxhighlight>
 
{{out}}
Line 521:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 541:
fmt.Println(macLookUp("BC:5F:F4"))
}
</syntaxhighlight>
</lang>
{{Out}}
<pre>Samsung Electronics Co.,Ltd
Line 552:
{{libheader|http-client}}
 
<langsyntaxhighlight lang="haskell">#!/usr/bin/env stack
{- stack
script
Line 598:
putStr $ printf "%-17s" mac ++ " = "
vendor <- lookupMac mgr mac
putStrLn vendor</langsyntaxhighlight>
 
{{Out}}
Line 611:
=={{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 669:
}
}
}</langsyntaxhighlight>
 
=={{header|Javascript}}==
<langsyntaxhighlight lang="javascript">
var mac = "88:53:2E:67:07:BE";
function findmac(){
Line 679:
 
findmac();
</syntaxhighlight>
</lang>
{{out}}
<pre>Intel Corporate</pre>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia"># v0.6.0
 
using Requests
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"]
println("$addr -> ", getvendor(addr))
end</langsyntaxhighlight>
 
{{out}}
Line 707:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.net.URL
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")
for (mac in macs) println(lookupVendor(mac))
}</langsyntaxhighlight>
 
{{out}}
Line 728:
=={{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 742:
]
bye
bye</langsyntaxhighlight>
{{Out}}
<pre>Intel Corporate
Line 751:
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">-- Requires LuaSocket extension by Lua
-- Created by James A. Donnell Jr.
-- www.JamesDonnell.com
Line 764:
 
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 792:
}
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|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 812:
</pre>
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">
<lang OCaml>
(* build with ocamlfind ocamlopt -package netclient -linkpkg macaddr.ml -o macaddr *)
 
Line 848:
 
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 860:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/env perl -T
use v5.18.2;
use warnings;
Line 928:
# }
# return;
#}</langsyntaxhighlight>
 
{{out}}
Line 943:
=={{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 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_global_cleanup</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 972:
=={{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 986:
}
curl_close($curl);
?></langsyntaxhighlight>
 
{{Out}}
Line 997:
=={{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 1,005:
(Invoke-WebRequest "$apiRoot/$_").Content
Start-Sleep 1.5
}</langsyntaxhighlight>
 
{{Out}}
Line 1,017:
{{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,031:
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">#lang racket
 
(require net/url)
Line 1,044:
"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,056:
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,080:
00:0d:4b
23:45:67
> -> $mac { say lookup $mac }</langsyntaxhighlight>
{{out}}
<pre>ASRock Incorporation
Line 1,090:
 
=={{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,098:
=={{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,123:
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,130:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project: MAC Vendor Lookup
 
Line 1,142:
url = download("api.macvendors.com/" + mac)
see url + nl
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,152:
 
=={{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,159:
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,168:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">extern crate reqwest;
 
use std::{thread, time};
Line 1,219:
}
}
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,229:
 
=={{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,236:
 
macs.foreach(mac => println(lookupVendor(mac)))
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
Line 1,242:
{{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,255:
(newline)
(map (lambda (burger) (sleep 2) (display (get-vendor burger)) (newline))
(cdr mac-addresses))</langsyntaxhighlight>
{{Out}}
<pre>Intel Corporate
Line 1,264:
 
=={{header|Tcl}}==
<langsyntaxhighlight Tcllang="tcl">package require http
 
# finally is a bit like go's defer
Line 1,283:
foreach mac {00-14-22-01-23-45 88:53:2E:67:07:BE} {
puts "$mac\t[maclookup $mac]"
}</langsyntaxhighlight>
{{out}}
Line 1,295:
{{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)
 
Line 1,306:
sleep 2
lookup "$burger"
done</langsyntaxhighlight>
 
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
 
Line 1,323:
sleep 2
curl -s "http://api.macvendors.com/$burger" && echo
done</langsyntaxhighlight>
 
And hey, just for completeness, let's toss in a [t]csh version:
 
{{works with|C Shell}}
<langsyntaxhighlight 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)
 
Line 1,337:
sleep 2
lookup "$burger"
end</langsyntaxhighlight>
 
{{out}}
Line 1,351:
 
=={{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,363:
wscript.echo mac & " -> " & WebRequest.ResponseText
next
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,372:
 
=={{header|Vlang}}==
<langsyntaxhighlight lang="vlang">import net.http
import time
 
Line 1,394:
resp := http.get("http://api.macvendors.com/" + mac) or {println('No data from server') return ''}
return resp.body.str()
}</langsyntaxhighlight>
 
{{out}}
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.
<langsyntaxhighlight lang="ecmascript">/* mac_vendor_lookup.wren */
class MAC {
foreign static lookup(address)
Line 1,414:
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_lookup.go */
package main
 
Line 1,455:
vm.InterpretFile(fileName)
vm.Free()
}</langsyntaxhighlight>
 
{{out}}
Line 1,466:
{{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,474:
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,486:
 
=={{header|Zoea}}==
<syntaxhighlight lang="zoea">
<lang Zoea>
program: mac_vendor_lookup
 
Line 1,494:
derive: 'http://api.macvendors.com/D4:F4:6F:C9:EF:8D'
output: 'Apple, Inc.'
</syntaxhighlight>
</lang>
 
=={{header|Zoea Visual}}==
10,327

edits