import socket

# Change the following host and see what IP it prints!
host = "disneyplus.com"
ip = socket.gethostbyname(host)

print(ip)
54.71.61.241
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((ip, 80))
    print("Successfully connected!")
Successfully connected!

Check-In

  1. What is an IP address? Answer: An address that is put in the browser. It is a numeric value assigned to a network device, and it is used for the identification and location of a network device.
  2. What is a TCP port? Answer: A transmission control protocal is a connection-oriented protocal. In networking, protocols are rules or standards that govern how data is transmitted between devices.
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((ip, 80))

    # Send a GET request to "/"
    s.sendall(b"GET / HTTP/1.1\r\n\r\n")

    # Recieve & print 2048 bytes of data
    data = s.recv(2048)
    print(data.decode())
HTTP/1.1 400 Bad Request
Date: Fri, 28 Apr 2023 05:16:04 GMT
Server: Apache/2.4.56 (Unix) OpenSSL/3.0.8
Content-Length: 226
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>

import requests

# Change the URL to whatever you'd like
response = requests.get("https://disney.com")

print("Status code:", response.status_code)
print("Headers:", response.headers)
print("Response text:", response.text[:100])

# Add a line to print the "Content-Type" header of the response
# Try an image URL!
Status code: 200
Headers: {'Content-Type': 'text/html;charset=utf-8', 'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff', 'x-ua-compatible': 'IE=edge,chrome=1', 'ETag': 'W/"bdeb0ac68371ff4846aa69c27521dca2"', 'Accept-Ranges': 'bytes', 'x-server': 'px-mh-ha-f', 'Content-Encoding': 'gzip', 'Content-Length': '91848', 'Cache-Control': 'public, max-age=1473', 'Expires': 'Fri, 28 Apr 2023 05:40:57 GMT', 'Date': 'Fri, 28 Apr 2023 05:16:24 GMT', 'Connection': 'keep-alive', 'Vary': 'Accept-Encoding', 'X-Origin': 'Matterhorn_TLS'}
Response text: <!DOCTYPE html>
<!--

    "We keep moving forward, opening up new doors and
      doing new things, 

NGINX

aws = "3.130.255.192"

response = requests.get("http://" + aws)
print(response.text)
<!doctype html>
<html>
<head>
<title>Cool site</title>
<meta name="description" content="cool site for apcsp">
</head>
<body>
Hello, this is my cool site. Check out my products:
<a href="/products">Products!!</a>
</body>
</html>

Configuration

server {
    // Listen on virtual "port 80"
    listen 80;
    listen [::]:80;
    server_name 3.130.255.192;

    location / {
        // Inform server about original client
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;

        // Forward all requests transparently to the server running on our computer
        proxy_pass              http://localhost:9099;
    }
}

Load Balancing

upstream example.com {
    server server1.example.com;
    server server1.example.com;
}

HTTP Headers

server {
    add_header X-Cool-Header "I love APCSP!";

    location /pages {
        add_header X-Cooler-Header "This is my secret header!";
    }
}

Check In

  1. Research 1 HTTP header and describe, in detail, its purpose.
  • This is an example of an HTTP header a user could include in their HTTP request:

  • User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36

  • This header is very useful for the server that needs to respond to the request. Since the user sent this information along with the request, it gives much more helpful information that can help the server with things like compatiability, security, and analyitics.

  1. Write a line in a sample NGINX configuration that will add that specific header to the /information location

using your code/server from earlier, I can add a specific header to the '/information' location with this code

```nginx server { add_header X-Cool-Header "I love music!";

location /pages { add_header X-Cooler-Header "This is my secret header!"; }

location /information { add_header Shruthi-Header "This is cool"; } }

  1. Explain the purpose of the load balancing performed by NGINX

Load balancing by NGINX distributes network traffic among many servers/computers. This improves efficiency, reliability and availability of the application.

  1. Modify the following code block to obtain the value of the secret header on /products of the AWS site
import requests

aws = "3.130.255.192"

response = requests.get("http://" + aws + "/products")

secret_header = response.headers.get('X-Cooler-Header')

print("The secret header is:", secret_header)
The secret header is: This is my secret header!

Hacks

  • Complete the above check-in questions and change the hosts (0.1)
  • Complete the above code-segment to retrieve the secret header (0.1)

Bonus (0.05)

Create a diagram showing the layers of abstraction that allow us to use HTTP (IP, TCP, etc.)

CORS Hacks

  1. Explain what CORS is and what it stands for

Answer: CORS stands for Cross-Origin Resource Sharing. It is a system, consisting of transmitting HTTP headers, that determines whether browsers block frontend JavaScript code from accessing responses for cross-origin resquests.

  1. Describe how you would be able to implement CORS into your own websites

Answer: To do this, open the server/index. js file and modify it to look like the following: const express = require("express"); const debug = require("debug")("server"); const app = express(); const port = process.

  1. Describe why you would want to implement CORS into your own websites

Answer: CORS allows more freedom and functionality than purely same-origin requests, but is more secure than simply allowing all cross-origin requests.

  1. How could use CORS to benefit yourself in the future?

Answer: I could use CORS to benefit myself in the future by being free to go to a restuarant with just my brother for dinner.

Total: 0.2 points

KASM Hacks

  1. What is the purpose of "sudo" when running commands in terminal?

Answer: The purpose of "sudo" when running commands in terminal is to get permission to run those commands.

  1. What are some commands which allow us to look at how the storage of a machine is set up as?

Answer: One of the commands which allows us to look at how the storage of a machine is set up as is df -H.

  1. What do you think are some alternatives to running "curl -O" to get the zip file for KASM?

Answer: Some alternatives to running "curl -O" are to manually download the zip file using "wget" or to download and transfer it through something like Google-Drive.

  1. What kind of commands do you think the "install.sh" command has and why is it necessary to call it?
  • Checking for system requirements

  • Downloading necessary files

  • Setting up environment

  • Installing necessary packages or libraries

"install.sh" is called to make the the installation process easier and more likely to be sucessful.

  1. Explain in at least 3-4 sentences how deploying KASM is related to/requires other topics talked about in the lesson and/or potential ways to add things mentioned in the lesson to this guide.

Answer: Deploying KASM, the container-based streaming service, requires several components such as headers, NGINX, load balancing, configuration, DNS, and CORS. Headers are important for configuring security settings and enabling CORS for KASM. NGINX is used as a reverse proxy to handle incoming web traffic and load balancing is necessary for distributing the traffic among multiple server instances running KASM. Configuration is required to set up the KASM service and define the specific settings for the environment in which it will run.

Total: 0.2 points