-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ps1
More file actions
35 lines (29 loc) · 1.32 KB
/
Copy pathserver.ps1
File metadata and controls
35 lines (29 loc) · 1.32 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
$http = [System.Net.HttpListener]::new()
$http.Prefixes.Add("http://*:80/")
$http.Start()
if ($http.IsListening) {
write-host "Ready Go!"
while ($http.IsListening) {
$context = $http.GetContext()
if ($context.Request.HttpMethod -eq 'GET') {
$timeStamp = Get-Date -Format o | ForEach-Object { $_ -replace ":", "." }
write-host "$($timeStamp)`t$($context.Request.UserHostAddress)`t$($context.Request.Url)" -f 'green'
$timeStamp = Get-Date -Format o | ForEach-Object { $_ -replace ":", "." }
[string]$html = "<h1>Hello World</h1><p>$($timeStamp)</>"
$buffer = [System.Text.Encoding]::UTF8.GetBytes($html)
$context.Response.ContentLength64 = $buffer.Length
$context.Response.OutputStream.Write($buffer, 0, $buffer.Length)
$context.Response.OutputStream.Close()
}
elseif ($context.Request.HttpMethod -eq 'PUT') {
$message = "$($timeStamp)`t$($context.Request.UserHostAddress)`t Stop Request"
write-host $message -f 'red';
$buffer = [System.Text.Encoding]::UTF8.GetBytes($message)
$context.Response.ContentLength64 = $buffer.Length
$context.Response.OutputStream.Write($buffer, 0, $buffer.Length)
$context.Response.OutputStream.Close()
$http.Stop()
}
}
}
$http.Dispose()