100% Guaranteed Results


DCF255 – Lab 6: HTTP Web Server Solved
$ 24.99
Category:

Description

5/5 – (1 vote)

Introduction:
This lab you will write a simple web server using PowerShell which will send an http response message containing an HTML file to the browser when receiving a http request to get the file.
This Lab requires a Windows computer or a Linux/Mac computer with Powershell installed.
Lab Procedure:
1. You will need to open PowerShell as administrator
2. Create a folder called HTTP in the root or in a Temp folder (use the cmdlet New-Item -Path
C:TempHTTP -ItemType Directory -Force
3. In the HTTP directory create a text file called MyWebPage.html . You can copy and paste the code.
<!DOCTYPE html>
<head><title>Lab6</title>
<style type=”text/css”> Body { background-color: gray;
}
H1 { color: white; text-align: center;
}
</style>
</head>
<body>
<H1>My First HTTP Response from MyPowerShellSite</H1>
<H1>Send by <type Your Name Here></H1>
</body>
</html>

4. In the same directory, you will create a simple HTTP server program. You can use a text editor, the PowerShell ISE or your favourite Powershell editor (Visual Studio Code is good) to create the file. The Powershell script is below, copy and paste the code into your Powershell script. Read the code comments to understand what it is doing.
This simple program will only make 1 connection. The client will send an http request for the file MyWebPage.html. The server will then check its local directory http for the file and send it to the browser. Since the file is a markup file with formatting the browser will display the formatted text. Name the file <SenecaID>_Lab6.ps1

#Simple HTTP Web Server
#creates Window Tile Description
$host.UI.RawUI.WindowTitle = “MyPowerShellSite”
#create http listener
$listener = New-Object System.Net.HttpListener
#server to listen on URL address localhost on port 8888. You can change the port if you want
$listener.Prefixes.Add(“http://localhost:8888/”)
#start the listener
$listener.Start()
#Sets the www root directory to the current directory
#Required to prevent traversal attacks using ….
New-PSDrive -Name MyPowerShellSite -PSProvider FileSystem -Root $PWD.Path
#using the get context method to create a synchronous object
$Context = $listener.GetContext()
#gets the files in the local path and sends to browser
$URL = $Context.Request.Url.LocalPath
$Content = Get-Content -Encoding Byte -Path “MyPowerShellSite:$URL”
$Context.Response.OutputStream.Write($Content, 0, $Content.Length)
$Context.Response.Close()

5. Once your server program is completed. Once the PowerShell console and navigate to the HTTP directory. Note: if you file does not run, any you get error messages, you will need to close PowerShell console, reopen it and start again.
6. Type: . <LearnName>_Lab6.ps1

Your server should now be running.
7. Open another PowerShell console window
8. Type the following: netstat -ano | select-string “8888”
What is protocol is used to make the connection? ______________
What is the status of the port? ________________
9. Open your browser
10. Type the following: http://localhost:8888/MyWebPage.html
It should look something like this:

If you modified the Powershell code to use a different port number, replace the port with the one you identified in the server program.
➢ Take a screen shot of the web page and paste it into this document with the answers to the questions below.

11. Type: netstat -ano | select-string “8888”

➢ What is/are the dynamic (source) port number(s)? _________________________

➢ What port numbers did the server use in the http response message to the browser? _________

➢ What is the status of the TCP ports? _____________

12. Close the browser window (not the Powershell Window)
13. Type: netstat -ano | select-string “8888” in the Powershell window.

➢ What is the status of the port numbers now? ________________
Submission Guidelines
Include the following documents in your submission to the Appropriate Lab Activity on Blackboard:
• <LearnName>_Lab06.pdf
o Please save the file as a PDF before submitting
o The document should contain a screenshot of the web page and answers to the questions o You do not need to include the .ps1 file or the .html file.

Reviews

There are no reviews yet.

Be the first to review “DCF255 – Lab 6: HTTP Web Server Solved”

Your email address will not be published. Required fields are marked *

Related products