Private/Download-MACPrefixList.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Function Download-MACPrefixList {

    <#
     
        .SYNOPSIS
        Downloads a copy of the MAC prefix list
 
        .DESCRIPTION
        Downloads a copy of the MAC prefix list from linuxnet.ca into a text file in the
        resources folder in the module root.
 
        .PARAMETER DownloadURL
        The URL to the MAC prefix list. Has a default value
 
        .PARAMETER OutputFileName
        The name of the file that will store the downloaded MAC prefix list
 
    #>


    [CmdletBinding()]
    Param (
        [Parameter(Position=0)]
        $DownloadURL = 'https://linuxnet.ca/ieee/oui/nmap-mac-prefixes',
        $OutputFileName = 'List.txt'
    )

    #Make a web request to the download URL. Split the results into an array, one index for each line break.
    $Response = ((Invoke-WebRequest -Uri $DownloadURL).Content -split "`n")

    #Take the reponse, and grab all lines except the last one (this makes parsing not fail later on).
    $Response = $Response[0..($Response.Length-2)]

    #Output the response to Resources folder
    $Response | Out-File $PSScriptRoot\..\Resources\$OutputFileName

}