IPTools.psm1
Function Show-IPv4Range { <# .SYNOPSIS Generate a list of IPv4 addresses between the first and the last IP address. .DESCRIPTION This function receives two IPv4 addresses and generate a list of IP addresses between the first and the last one. .EXAMPLE Show-IPv4Range -FirstIP 10.3.255.254 -LastIP 10.4.0.2 10.3.255.254 10.3.255.255 10.4.0.0 10.4.0.1 10.4.0.2 .PARAMETER FirstIP The first IPv4 address. .PARAMETER LastIP The last IPv4 address. .LINK https://github.com/brunobritorj .NOTES Author: Bruno B Silva - brunobritorj@outlook.com #> [CmdletBinding()] Param ( [Parameter(Mandatory=$True,Position=0,ValueFromPipeline=$True)] [IPAddress]$FirstIP, [Parameter(Mandatory=$True,Position=1,ValueFromPipeline=$True)] [IPAddress]$LastIP ) Process { $FirstIP.IPAddressToString While ($FirstIP -ne $LastIP) { If ($FirstIP.GetAddressBytes()[3] -ne 255) { $FirstIP.Address += 16777216 } Elseif ($FirstIP.GetAddressBytes()[2] -ne 255) { $FirstIP.Address += -4278124544 } Elseif ($FirstIP.GetAddressBytes()[1] -ne 255) { $FirstIP.Address += -4294901504 } Elseif ($FirstIP.GetAddressBytes()[0] -ne 255) { $FirstIP.Address += -4294967039 } Else { $LastIP = $FirstIP } $FirstIP.IPAddressToString } } } Function Show-SubnetAddressAndCIDR { <# .SYNOPSIS Show the subnet address for some IPv4 address. .DESCRIPTION This function receives an IPv4 address and its netmask to calculate what is its network address and CIDR prefix. .EXAMPLE Show-SubnetAddressAndCIDR -IPAddress 192.168.0.80 -NetMask 255.255.255.192 192.168.0.64/26 .PARAMETER IPv4 The IPv4 address. .PARAMETER NetMask The network mask for the IPv4 address. .LINK https://github.com/brunobritorj .NOTES Author: Bruno B Silva - brunobritorj@outlook.com #> [CmdletBinding()] Param ( [Parameter(Mandatory=$True,Position=0)][IPaddress]$IPAddress, [Parameter(Mandatory=$True,Position=1)][IPaddress]$NetMask ) Process { $Network = ([IPAddress]($IPAddress.Address -band $NetMask.Address)).IPAddressToString $CIDR = (([convert]::ToString($NetMask.Address, 2)) -replace 0).Length } End { Return $Network+'/'+$CIDR } } Function Get-MD5Hash { <# .SYNOPSIS Get the MD5 hash from some file. .DESCRIPTION This function receives a filename and returns the MD5 hash. .EXAMPLE Get-MD5Hash -File '.\YourFile.txt' 2D1DE770FD2832F0AE3E0928E19EA60A .PARAMETER File The file path\name that will be compared. .LINK https://github.com/brunobritorj .NOTES Author: Bruno B Silva - brunobritorj@outlook.com #> Param ( [Parameter(Mandatory=$True,ValueFromPipeline=$True)] [string]$File ) Process { $MD5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider $Hash = [System.BitConverter]::ToString($MD5.ComputeHash([System.IO.File]::ReadAllBytes($File))) -replace '-' } End { Return $Hash } } |