Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [System.Reflection.Assembly]::LoadWithPartialName("System.Web")
- Clear-Host
- $gigsToDownload = read-host "In gigabytes, how much data should I serve? (press enter for 4.5) "
- $gigsToDownload=[double]$gigsToDownload
- if( !($gigsToDownload -is [double] ) -Or $gigsToDownload -le 0) { $gigsToDownload=4.5 }
- Write-Host "Will serve " $gigsToDownload " GB."
- $data = [System.Text.Encoding]::UTF8.GetBytes( "".PadRight(16384,[char]0) )
- $serverAt="http://localhost:80/"
- $listener = New-Object System.Net.HttpListener
- $listener.Prefixes.Add($serverAt)
- $listener.Start()
- Write-Host "Now ready for requests to: " $serverAt
- do {
- $context = $listener.GetContext()
- $response = $context.Response
- Write-Host "now serving " $gigsToDownload " GBs of data..."
- $loopTo=[math]::Round( ($gigsToDownload * 1024 * 1024 *1024) / 16384)
- $response.ContentType = "application/octet-stream"
- $response.ContentLength64 = $data.Length * $loopTo;
- $response.Headers.Add("Content-Description: File Transfer")
- $response.Headers.Add("Content-Disposition: attachment; filename=dummyFile_" + $gigsToDownload + "GB.bin")
- $response.OutputStream.Flush()
- for ($i=0; $i -le $loopTo; $i++) {
- $response.OutputStream.Write($data, 0, $data.Length)
- If ($i % 100 -eq 0) { $response.OutputStream.Flush() }
- }
- $response.Close()
- Write-Host "served data with rCode: " $response.StatusCode
- } while ($listener.IsListening)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement