MAC vendor lookup: Difference between revisions
m
syntax highlighting fixup automation
mNo edit summary |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
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 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.
<
]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</
{{Out}}
Line 112:
=={{header|AppleScript}}==
<
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>
If this is part of a larger script you probably want to save and restore the text item delimiters:
<
set text item delimiters to linefeed
set tableText to table as string
set text item delimiters to savedTID
return tableText</
{{out}}
Line 150:
=={{header|Arturo}}==
<
print [mac "=>" read ~"http://api.macvendors.com/|mac|"]
pause 1500
]</
{{out}}
Line 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 183:
CLOSE NETWORK mynet
PRINT TOKEN$(info$, 2, "\r\n\r\n")</
{{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">
#include <curl/curl.h>
#include <string.h>
Line 267:
return EXIT_FAILURE;
}
</syntaxhighlight>
Invocation and output :
<pre>
Line 278:
=={{header|C sharp|C#}}==
<
using System.Net;
using System.Net.Http;
Line 297:
Console.ReadLine();
}
}</
{{out}}
Line 309:
=={{header|C++}}==
{{libheader|Boost}}
<
// the Boost documentation.
Line 371:
}
return EXIT_FAILURE;
}</
{{out}}
Line 380:
=={{header|Common Lisp}}==
<
(defun mac-vendor (mac)
Line 389:
(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 425:
Writeln(macLookUp('BC:5F:F4'));
readln;
end.</
{{out}}
<pre>Samsung Electronics Co.,Ltd
Line 432:
=={{header|Factor}}==
<
sequences threads ;
Line 442:
"FC:FB:FB:01:FA:21"
"10-11-22-33-44-55-66"
[ mac-vendor print 1 seconds sleep ] tri@</
{{out}}
<pre>
Line 451:
=={{header|FreeBASIC}}==
<
Var f = Freefile
Dim As String tmp
Line 476:
Next i
Sleep
</syntaxhighlight>
{{out}}
<pre>
Line 486:
=={{header|Free Pascal}}==
<
uses
Line 509:
end;
end;
end.</
{{out}}
Line 521:
=={{header|Go}}==
<
import (
Line 541:
fmt.Println(macLookUp("BC:5F:F4"))
}
</syntaxhighlight>
{{Out}}
<pre>Samsung Electronics Co.,Ltd
Line 552:
{{libheader|http-client}}
<
{- stack
script
Line 598:
putStr $ printf "%-17s" mac ++ " = "
vendor <- lookupMac mgr mac
putStrLn vendor</
{{Out}}
Line 611:
=={{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 669:
}
}
}</
=={{header|Javascript}}==
<
var mac = "88:53:2E:67:07:BE";
function findmac(){
Line 679:
findmac();
</syntaxhighlight>
{{out}}
<pre>Intel Corporate</pre>
=={{header|Julia}}==
<
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</
{{out}}
Line 707:
=={{header|Kotlin}}==
<
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))
}</
{{out}}
Line 728:
=={{header|Logo}}==
{{works with|UCB Logo}}
<
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</
{{Out}}
<pre>Intel Corporate
Line 751:
=={{header|Lua}}==
<
-- Created by James A. Donnell Jr.
-- www.JamesDonnell.com
Line 764:
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 792:
}
Checkit
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
Examples:<
Outputs:<pre>Dell Inc.</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 812:
</pre>
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">
(* build with ocamlfind ocamlopt -package netclient -linkpkg macaddr.ml -o macaddr *)
Line 848:
</syntaxhighlight>
{{out}}
<pre>
Line 860:
=={{header|Perl}}==
<
use v5.18.2;
use warnings;
Line 928:
# }
# return;
#}</
{{out}}
Line 943:
=={{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 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>
<!--</
{{out}}
<pre>
Line 972:
=={{header|PHP}}==
{{trans|AppleScript}}
<
$apiRoot = "https://api.macvendors.com";
$macList = array("88:53:2E:67:07:BE", "D4:F4:6F:C9:EF:8D",
Line 986:
}
curl_close($curl);
?></
{{Out}}
Line 997:
=={{header|PowerShell}}==
{{trans|AppleScript}}
<
$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
}</
{{Out}}
Line 1,017:
{{libheader|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 1,031:
=={{header|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))))</
{{out}}
Line 1,056:
Apparently there is some rate limiting on place now, sleep a bit between requests.
<syntaxhighlight lang="raku"
my $ua = HTTP::UserAgent.new;
Line 1,080:
00:0d:4b
23:45:67
> -> $mac { say lookup $mac }</
{{out}}
<pre>ASRock Incorporation
Line 1,090:
=={{header|Red}}==
<
</syntaxhighlight>
{{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.
<
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. */</
{{out|output|text= when using the default input:}}
<pre>
Line 1,130:
=={{header|Ring}}==
<
# Project: MAC Vendor Lookup
Line 1,142:
url = download("api.macvendors.com/" + mac)
see url + nl
</syntaxhighlight>
Output:
<pre>
Line 1,152:
=={{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,159:
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,168:
=={{header|Rust}}==
<
use std::{thread, time};
Line 1,219:
}
}
</syntaxhighlight>
Output:
<pre>
Line 1,229:
=={{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,236:
macs.foreach(mac => println(lookupVendor(mac)))
}</
=={{header|Scheme}}==
Line 1,242:
{{works with|Chicken Scheme}}
{{libheader|http-client}}
<
(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))</
{{Out}}
<pre>Intel Corporate
Line 1,264:
=={{header|Tcl}}==
<
# 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]"
}</
{{out}}
Line 1,295:
{{works with|Z Shell}}
Surprising that nobody had implemented the Bash / Shell version yet.
<
4c:72:b9:56:fe:bc 00-14-22-01-23-45)
Line 1,306:
sleep 2
lookup "$burger"
done</
It can be made to work in a pure-POSIX shell without array variables:
{{works with|Bourne Shell}}
{{works with|Almquist Shell}}
<
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</
And hey, just for completeness, let's toss in a [t]csh version:
{{works with|C Shell}}
<
4c:72:b9:56:fe:bc 00-14-22-01-23-45)
Line 1,337:
sleep 2
lookup "$burger"
end</
{{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>
Output:
<pre>
Line 1,372:
=={{header|Vlang}}==
<
import time
Line 1,394:
resp := http.get("http://api.macvendors.com/" + mac) or {println('No data from server') return ''}
return resp.body.str()
}</
{{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.
<
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"))</
which we embed in the following Go program and run it.
{{libheader|WrenGo}}
<
package main
Line 1,455:
vm.InterpretFile(fileName)
vm.Free()
}</
{{out}}
Line 1,466:
{{trans|Lua}}
Uses libcurl (the multiprotocol file transfer library) to do the web query
<
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)
}</
<
lookUp("4c:72:b9:56:fe:bc").println();
lookUp("foobar").println();</
{{out}}
<pre>
Line 1,486:
=={{header|Zoea}}==
<syntaxhighlight lang="zoea">
program: mac_vendor_lookup
Line 1,494:
derive: 'http://api.macvendors.com/D4:F4:6F:C9:EF:8D'
output: 'Apple, Inc.'
</syntaxhighlight>
=={{header|Zoea Visual}}==
|