-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuickHost.ps1
47 lines (37 loc) · 1.31 KB
/
QuickHost.ps1
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
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
[System.Windows.Forms.Application]::VisualStyleState = [System.Windows.Forms.VisualStyles.VisualStyleState]::NoneEnabled
$header = @"
HTTP/1.1 200 OK
Content-Type: text/plain; charset=UTF-8
Content-Length: XXX
Connection: close
"@
$listener = [System.Net.Sockets.TcpListener]::new([System.Net.IPAddress]::Any, 42069)
$form = [System.Windows.Forms.Form]::new()
$form.Text = "Quick Host"
$form.Width = $form.Height = 500
$textbox = [System.Windows.Forms.TextBox]::new()
$textbox.Multiline = $true
$textbox.Width = 450
$textbox.Height = 380
$textbox.Location = [System.Drawing.Point]::new(25, 25)
$form.Controls.Add($textbox)
$button = [System.Windows.Forms.Button]::new()
$button.Text = "Start Hosting"
$button.Width = 450
$button.Height = 25
$button.Location = [System.Drawing.Point]::new(25, 420)
$button.Add_Click({
$listener.Start()
$client = $listener.AcceptTcpClient()
$stream = $client.GetStream()
$listener.Stop()
$response = $header.Replace("Content-Length: XXX","Content-Length: $($textbox.Text.Length)")+$textbox.Text
$buffer = [System.Text.Encoding]::UTF8.GetBytes($response)
$stream.Write($buffer, 0, $buffer.Length)
$stream.close()
$client.Close()
})
$form.Controls.Add($button)
$form.ShowDialog()