Advertisement
easternnl

SSL connection measurement

Jan 4th, 2019
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. add-type @"
  4.    using System.Net;
  5.    using System.Security.Cryptography.X509Certificates;
  6.    public class TrustAllCertsPolicy : ICertificatePolicy {
  7.        public bool CheckValidationResult(
  8.            ServicePoint srvPoint, X509Certificate certificate,
  9.            WebRequest request, int certificateProblem) {
  10.            return true;
  11.        }
  12.    }
  13. "@
  14. [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
  15.  
  16. $url = $args[0]
  17. if ($args[1]) { [int]$keepalive = $args[1] } else { $keepalive = 15 }
  18. $progressPreference = 'silentlyContinue'
  19.  
  20.  
  21. write-host "Creating initial connection to $url" -NoNewline
  22. $initialconnection = measure-command {
  23.     $result = Invoke-WebRequest -Uri $url -UseBasicParsing
  24.     }
  25. write-host -ForegroundColor Green " Done"
  26.  
  27.  
  28. if ($result.Headers["Keep-Alive"] -match "timeout=([0-9]{0,3})")
  29. {
  30.     [int]$keepalive = $Matches[1]
  31.     $keepalive = $keepalive + 2
  32.     write-host "Waiting $keepalive seconds to let the server clear the connection"
  33. }
  34. else
  35. {
  36.     write-host "Waiting DEFAULT $keepalive seconds to let the server clear the connection"
  37.    
  38. }
  39. sleep $keepalive
  40.  
  41.  
  42.  
  43.  
  44. write-host "Creating session resumption request to $url" -NoNewline
  45. $resumeconnection = measure-command {
  46.     $result = Invoke-WebRequest -Uri $url -UseBasicParsing
  47.     }
  48. write-host -ForegroundColor Green " Done"
  49.  
  50. write-host "Creating keepalive request to $url" -NoNewline
  51. $keepaliverequest = measure-command {
  52.     $result = Invoke-WebRequest -Uri $url -UseBasicParsing
  53.     }
  54. write-host -ForegroundColor Green " Done"
  55.  
  56.  
  57. write-host "Initial connection: " $initialconnection.TotalMilliseconds
  58. write-host "Resume connection: " $resumeconnection.TotalMilliseconds
  59. write-host "KeepAlive request: " $keepaliverequest.TotalMilliseconds
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement