-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStart-WebTrafficLoad.ps1
More file actions
76 lines (65 loc) · 2.11 KB
/
Start-WebTrafficLoad.ps1
File metadata and controls
76 lines (65 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<#
.Synopsis
Used to generate traffic against a provided url
.DESCRIPTION
Generate a web load against a url
.EXAMPLE
Start-WebTrafficLoad.ps1 -Url www.google.com -NumOfRuns 100 -UseSsl -WithTimeout
.EXAMPLE
Start-WebTrafficLoad.ps1 -Url www.yahoo.com -NumOfRuns 10
#>
[CmdletBinding()]
Param
(
# url to target load against
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$Url,
# number of times to hit the target page
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=1)]
[int]$NumOfRuns,
# use if the target requires ssl connections
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
Position=2)]
[switch]$UseSsl,
# use if it is desired to pause between each HTTP GET
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
Position=3)]
[switch]$WithTimeout
)
if($UseSsl.IsPresent){
$Uri = "https://$Url/"
}
else{
$Uri = "http://$Url/"
}
$i = 0
while ($i -le $NumOfRuns) {
try {
[net.httpWebRequest]
$req = [net.webRequest]::create($Uri)
$req.method = "GET"
$req.ContentType = "application/x-www-form-urlencoded"
$req.TimeOut = 60000
$start = get-date
[net.httpWebResponse] $res = $req.getResponse()
$timetaken = ((get-date) - $start).TotalMilliseconds
Write-Output $res.Content
Write-Output ("{0} Status Code: {1} ResponseTime: {2}" -f (get-date), $res.StatusCode.value__, $timetaken)
$req = $null
$res.Close()
$res = $null
} catch [Exception] {
Write-Output ("{0} {1}" -f (get-date), $_.ToString()) | ft -AutoSize
}
$req = $null
if($WithTimeout.IsPresent){
Start-Sleep -Milliseconds 200
}
$i++
}