Advertisement
upz

Check-IP

upz
Apr 19th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Check-IP
  2. {
  3. PARAM
  4. (
  5.     $ip
  6. )
  7.     try
  8.     {
  9.         [System.Net.IPAddress]$ip1 = $ip
  10.         if ($ip1.AddressFamily -match 'v6')
  11.         {
  12.             $type = 'IPv6'
  13.         }
  14.         else
  15.         {
  16.             $type = 'IPv4'
  17.             if (($ip.Split('.')).count -ne 4)
  18.             {
  19.                 Write-Host -ForegroundColor Red "$ip" -NoNewline
  20.                 Write-Host -ForegroundColor White " - " -NoNewline
  21.                 Write-Host -ForegroundColor Gray "is not a valid $type address"
  22.                 break;
  23.             }
  24.         }
  25.         Write-Host -ForegroundColor Green "$ip" -NoNewline
  26.         Write-Host -ForegroundColor White " - " -NoNewline
  27.         Write-Host -ForegroundColor Gray "is a Valid $type address"
  28.     }
  29.     catch
  30.     {
  31.         if ($type -eq $null)
  32.         {$type = 'IPv6'}
  33.         Write-Host -ForegroundColor Red "$ip" -NoNewline
  34.         Write-Host -ForegroundColor White " - " -NoNewline
  35.         Write-Host -ForegroundColor Gray "is not a valid $type address"
  36.         break;      
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement