MAC vendor lookup: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) m →{{header|Perl 6}}: Add rate limiting. |
|||
Line 450: | Line 450: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{works with|Rakudo| |
{{works with|Rakudo|2018.03}} |
||
Apparently there is some rate limiting on place now, sleep a bit between requests. |
|||
<lang perl6>use HTTP::UserAgent; |
<lang perl6>use HTTP::UserAgent; |
||
my $ua = HTTP::UserAgent.new; |
my $ua = HTTP::UserAgent.new; |
||
$ua.timeout = 10; # seconds |
$ua.timeout = 10; # seconds |
||
my $server = 'http://api.macvendors.com/'; |
my $server = 'http://api.macvendors.com/'; |
||
sub lookup ($mac) { |
sub lookup ($mac) { |
||
my $response = $ua.get: "$server+$mac"; |
my $response = $ua.get: "$server+$mac"; |
||
sleep 1; |
|||
return $response.is-success ?? $response.content !! 'N/A'; |
return $response.is-success ?? $response.content !! 'N/A'; |
||
CATCH { # Normally you would report some information about what |
CATCH { # Normally you would report some information about what |
||
default { Nil } # went wrong, but the task specifies to ignore errors. |
default { Nil } # went wrong, but the task specifies to ignore errors. |
||
} |
} |
||
} |
} |
||
for < |
for < |
||
BC:5F:F4 |
BC:5F:F4 |
||
FC-A1-3E |
FC-A1-3E |
||
10:dd:b1 |
10:dd:b1 |
||
00 |
00:0d:4b |
||
23:45:67 |
23:45:67 |
||
> -> $mac { say lookup $mac }</lang> |
> -> $mac { say lookup $mac }</lang> |