validates IP address


posted by Tobias Weltner
11-26-2008

Downloads: 309
File size: 216 B
Views: 1,215

Embed
validates IP address
  1. function isIPAddress($object) {  
  2.     ($object -as [System.Net.IPAddress]).IPAddressToString -eq $object -and $object -ne $null 
  3.  
  4. isIPAddress "10" 
  5. isIPAddress "127.0.0.1" 
  6. IsIPAddress "hello" 
  7. isIPAddress $null 
function isIPAddress returns $true for valid IP addresses, otherwise $false. It validates IP addresses using the System.Net.IPAddress type conversion and also accepts V6 IP addresses.
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.