MAC vendor lookup: Difference between revisions

Content added Content deleted
(Ada version)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 76: Line 76:
{{out}}
{{out}}
<pre>Hon Hai Precision Ind. Co.,Ltd.</pre>
<pre>Hon Hai Precision Ind. Co.,Ltd.</pre>



=={{header|C}}==
=={{header|C}}==
Line 209: Line 208:
(error "~%Not a MAC address: ~a" mac))))
(error "~%Not a MAC address: ~a" mac))))
</lang>
</lang>



=={{header|Free Pascal}}==
=={{header|Free Pascal}}==
Line 396: Line 394:
}
}
}</lang>
}</lang>



=={{header|Javascript}}==
=={{header|Javascript}}==
Line 409: Line 406:
{{out}}
{{out}}
<pre>Intel Corporate</pre>
<pre>Intel Corporate</pre>




=={{header|Julia}}==
=={{header|Julia}}==
Line 470: Line 465:
local macAddress = "FC-A1-3E-2A-1C-33"
local macAddress = "FC-A1-3E-2A-1C-33"
print(lookup(macAddress))</lang>
print(lookup(macAddress))</lang>

=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
<lang M2000 Interpreter>
<lang M2000 Interpreter>
Line 497: Line 493:
Checkit
Checkit
</lang>
</lang>

=={{header|Mathematica}}==
=={{header|Mathematica}}==
<lang Mathematica>macLookup[mac_String] := Quiet[Check[Import["http://api.macvendors.com/" <> mac], "N/A"]]</lang>
<lang Mathematica>macLookup[mac_String] := Quiet[Check[Import["http://api.macvendors.com/" <> mac], "N/A"]]</lang>
Line 594: Line 591:
FC:FB:FB:01:FA:21 = Cisco Systems, Inc
FC:FB:FB:01:FA:21 = Cisco Systems, Inc
BC:5F:F4 = ASRock Incorporation</pre>
BC:5F:F4 = ASRock Incorporation</pre>

=={{header|Perl 6}}==
{{works with|Rakudo|2018.03}}
Apparently there is some rate limiting on place now, sleep a bit between requests.

<lang perl6>use HTTP::UserAgent;
my $ua = HTTP::UserAgent.new;
$ua.timeout = 10; # seconds
my $server = 'http://api.macvendors.com/';
sub lookup ($mac) {
my $response = $ua.get: "$server+$mac";
sleep 1;
return $response.is-success ?? $response.content !! 'N/A';
CATCH { # Normally you would report some information about what
default { Nil } # went wrong, but the task specifies to ignore errors.
}
}
for <
BC:5F:F4
FC-A1-3E
10:dd:b1
00:0d:4b
23:45:67
> -> $mac { say lookup $mac }</lang>
{{out}}
<pre>ASRock Incorporation
Samsung Electronics Co.,Ltd
Apple, Inc.
Roku, Inc.
N/A
</pre>


=={{header|Phix}}==
=={{header|Phix}}==
Line 706: Line 666:
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.</pre>
D4:F4:6F:C9:EF:8D Apple, Inc.</pre>

=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.03}}
Apparently there is some rate limiting on place now, sleep a bit between requests.

<lang perl6>use HTTP::UserAgent;
my $ua = HTTP::UserAgent.new;
$ua.timeout = 10; # seconds
my $server = 'http://api.macvendors.com/';
sub lookup ($mac) {
my $response = $ua.get: "$server+$mac";
sleep 1;
return $response.is-success ?? $response.content !! 'N/A';
CATCH { # Normally you would report some information about what
default { Nil } # went wrong, but the task specifies to ignore errors.
}
}
for <
BC:5F:F4
FC-A1-3E
10:dd:b1
00:0d:4b
23:45:67
> -> $mac { say lookup $mac }</lang>
{{out}}
<pre>ASRock Incorporation
Samsung Electronics Co.,Ltd
Apple, Inc.
Roku, Inc.
N/A
</pre>


=={{header|Ring}}==
=={{header|Ring}}==
Line 744: Line 742:
23:45:67 Vendor not found
23:45:67 Vendor not found
</pre>
</pre>



=={{header|Rust}}==
=={{header|Rust}}==
Line 806: Line 803:
N/A
N/A
</pre>
</pre>

=={{header|Scala}}==
=={{header|Scala}}==
<lang scala>object LookUp extends App {
<lang scala>object LookUp extends App {
Line 815: Line 813:
macs.foreach(mac => println(lookupVendor(mac)))
macs.foreach(mac => println(lookupVendor(mac)))
}</lang>
}</lang>

=={{header|Tcl}}==
=={{header|Tcl}}==
<lang Tcl>package require http
<lang Tcl>package require http