PoshCode Logo PowerShell Code Repository

Get-BogonList by Rich Kusak 20 months ago (modification of post by Rich Kusak view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1892"></script>download | new post

Heres a script to quickly look up the latest version of the bogon list maintained by Team Cymru from within PowerShell.

  1. function Get-BogonList {
  2. <#
  3.         .SYNOPSIS
  4.                 Gets the bogon list.
  5.        
  6.         .DESCRIPTION
  7.                 The Get-BogonList function retrieves the bogon prefix list maintained by Team Cymru.
  8.                
  9.                 A bogon prefix is a route that should never appear in the Internet routing table.
  10.                 A packet routed over the public Internet (not including over VPNs or other tunnels) should never have a source address in a bogon range.
  11.                 These are commonly found as the source addresses of DDoS attacks. Bogons are defined as Martians (private and reserved addresses defined by RFC 1918 and RFC 5735) and
  12.                 netblocks that have not been allocated to a regional internet registry (RIR) by the Internet Assigned Numbers Authority.
  13.                
  14.         .PARAMETER Aggregated
  15.                 By default the unaggregated bogon list is retrieved. Use this switch parameter to retrieve the aggregated list.
  16.        
  17.         .OUTPUTS
  18.                 PSObject
  19.        
  20.         .EXAMPLE
  21.                 Get-BogonList
  22.                 Retrieves the unaggregated bogon list from Team Cymru.
  23.                
  24.         .EXAMPLE
  25.                 Get-BogonList -Aggregated
  26.                 Retrieves the aggregated bogon list from Team Cymru.
  27.        
  28.         .NOTES
  29.                 Name: Get-BogonList
  30.                 Author: Rich Kusak (rkusak@cbcag.edu)
  31.                 Created: 2010-01-31
  32.                 LastEdit: 2010-06-02 13:22
  33.                 Version: 1.1.0
  34.                
  35.                 #Requires -Version 2.0
  36.                
  37.         .LINK
  38.                 http://www.team-cymru.org/Services/Bogons/
  39.  
  40. #>
  41.        
  42.         [CmdletBinding()]
  43.         param (
  44.                 [switch]$Aggregated
  45.         )
  46.        
  47.         # Create a web client object
  48.         $webClient = New-Object System.Net.WebClient
  49.        
  50.         # Parse the bogons sites for the last updated date and current version
  51.         $version = $webClient.DownloadString('http://www.team-cymru.org/Services/Bogons/') -split "`n" |
  52.                 Where-Object {$_ -match 'Bogons Last Updated:' -or $_ -match 'Current version:'} |
  53.                 ForEach-Object {$_.ToString().Replace('<strong>',"").Replace('</strong><br />',"").Trim()}
  54.        
  55.         # Display title and version information
  56.         Write-Host "Team Cymru Bogon List" ; $version
  57.        
  58.         # Retrieve and display the aggregated bogon list
  59.         if ($Aggregated) {
  60.                 foreach ($bogon in $webClient.DownloadString('http://www.team-cymru.org/Services/Bogons/bogon-bn-agg.txt') -split "`n") {
  61.                         New-Object PSObject -Property @{'Aggregated Bogons' = $bogon}
  62.                 }
  63.  
  64.         # Retrieve and display the unaggregated bogon list
  65.         } else {
  66.                 foreach ($bogon in $webClient.DownloadString('http://www.team-cymru.org/Services/Bogons/bogon-bn-nonagg.txt') -split "`n") {
  67.                         New-Object PSObject -Property @{'Unaggregated Bogons' = $bogon}
  68.                 }
  69.         }
  70. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me