From 8eaa2c996aa824e9d448947e5d345a27107ae33c Mon Sep 17 00:00:00 2001 From: Jordan Goulder Date: Fri, 6 Dec 2024 21:41:47 -0500 Subject: [PATCH] Initial commit --- LICENSE.txt | 22 +++++++++++++++++++++ README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ ncws.sh | 26 +++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100755 ncws.sh diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..e37f480 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2024 Jordan Goulder + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..669401b --- /dev/null +++ b/README.md @@ -0,0 +1,56 @@ +# netcat Web Server + +Serve a web page and inspect HTTP requests using `netcat`. + +## Usage + +1. After cloning the repository, make sure that the `ncws.h` script is executable. +````sh +$ chmod +x ncws.h +```` + +3. Run the `ncws.h` script. +````sh +$ ./ncws.h +netcat web server +Listening on 0.0.0.0 8080 +```` + +4. In another terminal, make a request to the server using `curl`. +````sh +$ curl http://127.0.0.1:8080 +```` + +5. `netcat` will print the request and send a response. +````sh +... +Connection received on localhost 40790 +GET / HTTP/1.1 +Host: 127.0.0.1:8080 +User-Agent: curl/8.11.0 +Accept: */* +```` + +6. `curl` should receive the response and print it. +````sh +$ curl http://127.0.0.1:8080 + + + + + + Hello, World! + + +

Hello, World!

+ + +```` + +7. The script will then resume listening for more requests. +````sh +... +Listening on 0.0.0.0 8080 +```` + +8. Press `CTRL-C` to terminate the script. diff --git a/ncws.sh b/ncws.sh new file mode 100755 index 0000000..0332a43 --- /dev/null +++ b/ncws.sh @@ -0,0 +1,26 @@ +#!/bin/env bash + +read -r -d '' HTML << EOM +HTTP/1.1 200 OK +Content-Type: text/html; +Server: netcat + + + + + + + Hello, World! + + +

Hello, World!

+ + + +EOM + +echo "netcat web server" + +while true; do + printf '%s' "$HTML" | netcat -v -N -l 8080; +done