MAC vendor lookup: Difference between revisions

→‎{{header|AppleScript}}: Do the appending and delaying in AS instead of shell
m (Thundergnat moved page MAC Vendor Lookup to MAC vendor lookup: capitalization policy (don't know how I missed this one for so long...))
(→‎{{header|AppleScript}}: Do the appending and delaying in AS instead of shell)
Line 63:
 
=={{header|AppleScript}}==
This is the first implementation to build in a delay between two calls to avoid throttling by macvendors.com. The version below is the as-typed one :
<lang AppleScript>set apiRoot to "https://api.macvendors.com"
set {table, macList} to {{return}, {"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"}}¬
set {table, macList} to {{return}, {"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"}}
 
set table to {}
repeat with burger in macList
set end of table to do shell script "curl http://api.macvendors.com/" & burgerapiRoot & " && sleep 5 && echo '\n'/" & returnburger
delay 1.5
end repeat
 
set text item delimiters to linefeed
return table as string
</lang>
 
If this is part of a larger script you probably want to save and restore the text item delimiters:
Which will turn into the one below once it is compiled. Script Editor translates \n to a newline in the code itself.
<lang AppleScript>
set {table, macList} to {{return}, {"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"}}
 
<lang applescript>set savedTID to text item delimiters
repeat with burger in macList
set text item delimiters to linefeed
set end of table to do shell script "curl http://api.macvendors.com/" & burger & " && sleep 5 && echo '
returnset tableText to table as string
'" & return
set text item delimiters to savedTID
end repeat
return tableText</lang>
 
return table as string
</lang>
 
{{out}}
<pre>
"
Intel Corporate
Apple, Inc.
Line 94 ⟶ 93:
PEGATRON CORPORATION
Dell Inc.
"
</pre>
 
1,480

edits