|
# Find Raspberries on Network |
|
|
|
# Note: This is currently very slow. Use a tool like "Angry IP Scanner" instead. |
|
|
|
<# |
|
.SYNOPSIS |
|
Returns an array of IP Addresses based on a start and end address |
|
|
|
.DESCRIPTION |
|
Returns an array of IP Addresses based on a start and end address |
|
|
|
.PARAMETER Start |
|
Starting IP Address |
|
|
|
.PARAMETER End |
|
Ending IP Address |
|
|
|
.PARAMETER Exclude |
|
Exclude addresses with this final octet |
|
|
|
Default excludes 0, 1, and 255 |
|
|
|
e.g. 5 excludes *.*.*.5 |
|
|
|
.EXAMPLE |
|
New-IPRange -Start 192.168.1.5 -End 192.168.20.254 |
|
|
|
Create an array from 192.168.1.5 to 192.168.20.254, excluding *.*.*.[0,1,255] (default exclusion) |
|
|
|
.NOTES |
|
Modified version of the version used in the WFTools package. |
|
Install-Module WFTools -Force -AllowClobber -Confirm:$false; |
|
Import-Module WFTools; |
|
|
|
.FUNCTIONALITY |
|
Network |
|
#> |
|
function New-IpRange |
|
{ |
|
param( |
|
[Parameter(Mandatory = $true, Position = 0)] |
|
[System.Net.IPAddress]$Start, |
|
|
|
[Parameter(Mandatory = $true, Position = 1)] |
|
[System.Net.IPAddress]$End, |
|
|
|
[int[]]$Exclude = @( 0, 1, 255 ) |
|
) |
|
process{ |
|
for($currentIP = $startIP.Address; $currentIP -le $endIp.Address; $currentIP++){ |
|
|
|
$IPBytes = ([System.Net.IPAddress]$currentIP).GetAddressBytes(); |
|
[Array]::Reverse($IPBytes); |
|
if($Exclude -notcontains $IPBytes[3]) |
|
{ |
|
$IPToPing = [System.Net.IPAddress]$currentIP; |
|
Write-Output $IPToPing; |
|
} |
|
} |
|
} |
|
} |
|
|
|
function Ping-IpAddress |
|
{ |
|
[cmdletbinding()] |
|
param( |
|
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] |
|
[System.Net.IPAddress]$Address |
|
) |
|
process { |
|
$Timeout = 10; |
|
$Ping = New-Object System.Net.NetworkInformation.Ping; |
|
$Response = $Ping.Send($Address, $Timeout); |
|
Write-Output $Response; |
|
} |
|
} |
|
|
|
$startIP = [System.Net.IPAddress]"10.0.0.0"; |
|
$endIP = [System.Net.IPAddress]"10.0.0.255"; |
|
New-IpRange -Start $startIP -End $endIP | Ping-IpAddress | where ($_.Status -ne "TimedOut") | select -Property Address |