PoshCode Logo PowerShell Code Repository

Get-BogonList (modification of post by Rich Kusak view diff)
View followups from Rich Kusak | diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1622"></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. <#
  2.         .SYNOPSIS
  3.                 Gets the bogon list.
  4.        
  5.         .DESCRIPTION
  6.                 The Get-BogonList script retrieves the bogon prefix list maintained by Team Cymru.
  7.                
  8.                 A bogon prefix is a route that should never appear in the Internet routing table.
  9.                 A packet routed over the public Internet (not including over VPNs or other tunnels) should never have a source address in a bogon range.
  10.                 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 3330) and
  11.                 netblocks that have not been allocated to a regional internet registry (RIR) by the Internet Assigned Numbers Authority.
  12.                
  13.         .PARAMETER Aggregated
  14.                 By default the unaggregated bogon list is retrieved. Use this switch parameter to retrieve the aggregated list.
  15.        
  16.         .OUTPUTS
  17.                 PSObject
  18.        
  19.         .EXAMPLE
  20.                 Get-BogonList
  21.                 Retrieves the unaggregated bogon list from Team Cymru.
  22.                
  23.         .EXAMPLE
  24.                 Get-BogonList -Aggregated
  25.                 Retrieves the aggregated bogon list from Team Cymru.
  26.        
  27.         .NOTES
  28.                 Name: Get-BogonList
  29.                 Author: Rich Kusak (rkusak@cbcag.edu)
  30.                 Created: 2010-01-31
  31.                 Version: 1.0.0
  32.                
  33.                 #Requires -Version 2.0
  34.                
  35.         .LINK
  36.                 http://www.team-cymru.org/Services/Bogons/
  37.  
  38. #>
  39.        
  40.         param (
  41.                 [switch]$Aggregated
  42.         )
  43.        
  44.         $webClient = New-Object System.Net.WebClient
  45.        
  46.         $version = $webClient.DownloadString("http://www.cymru.com/Documents/bogon-list.html") -split "`n" |
  47.                 Where-Object {$_ -cmatch "TITLE"} | ForEach-Object {$_.Remove(0,7).Replace('</TITLE>',"").Trim()}
  48.        
  49.         if ($Aggregated) {
  50.                 foreach ($bogon in $webClient.DownloadString("http://www.cymru.com/Documents/bogon-bn-agg.txt") -split "`n" | Where-Object {$_ -notlike $null}) {
  51.                         New-Object PSObject -Property @{$version = $bogon}
  52.                 }
  53.         } else {
  54.                 foreach ($bogon in $webClient.DownloadString("http://www.cymru.com/Documents/bogon-bn-nonagg.txt") -split "`n" | Where-Object {$_ -notlike $null}) {
  55.                         New-Object PSObject -Property @{$version = $bogon}
  56.                 }
  57.         }

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