Wednesday, July 27, 2016

PowerShell v3 Function Test Uri

As part of the security module I am working on I thought some Uri testing would be a good analysis tool. This function is merely a subroutine, but, still is worth pointing out:
function Test-Uri
{
      <#
            .NOTES
                  Author: Will Steele
                  Last Modified Date: 07/27/2012
                 
            .EXAMPLE
                  Test-Uri -Uri http://www.msn.com
                  True
           
            .EXAMPLE
                  Test-Uri -Uri http:/hax0r.com
                  False
      #>
     
      param(
            [ValidateNotNullOrEmpty()]
            [String]
            $Uri 
      )
     
      if([System.Uri]::IsWellFormedUriString($Uri, [System.UriKind]::RelativeOrAbsolute))
      {
            [System.Uri]::TryCreate($Uri, [System.UriKind]::RelativeOrAbsolute, [ref] $uri)
      }
      else
      {
            $false
      }
}
The two key lines here are the  IsWellFormedUriString and  TryCreate . You can get more details about how these work from MSDN.

  • IsWellFormedUriString:  Uri.IsWellFormedUriString Method
  • TryCreate:  Uri.TryCreate Method (String, UriKind, Uri%)
Again, this is a simple function, but, highly useful for anyone doing pen testing, analysis, checks, etc.

Related Post:

0 comments:

Post a Comment

 
Copyright 2009 Information Blog
Powered By Blogger