HTTP and HTML tools

Quick one-page serving web server

This snippet uses nc (netcat) to strictly serve index.html over port 8888. Parameterize or modify to your liking.

while true; do
    echo -e "HTTP/1.1 200 OK\nContent-Type: text/html\n\
Content-Length: $(du -b index.html | awk '{print $1}')\n\
Connection: close\n\n $(cat index.html)\r\n" |
    nc -lp 8888
    sleep 1

HTML listing via Tree

Build a one-page directory listing of your entire site, sorted by mod time.

tree -I index.html --matchdirs -t -H base_url \
     -T "Dir Listing" --noreport . > tree.html

The few key arguments to the tree command:

Create a recursive html directory listing for your entire site.

tree -R -L 1 --dirsfirst -H base_url \
     -T "Dir Listing" --noreport . > tree.html

Create a test html directory hierarchy with index.html files

# Create the directories
mkdir -p top{1,2}/middle{1,2}/bottom{1,2} -v

for dir in $(find -type d); do echo "$dir: hello" > $dir/index.html; done

# Or

echo "hello" > index.html
find -type d -exec cp -v index.html {} \;


Log into site via HTTP POST and save cookie.

curl --cookie-jar cookie.txt '' \
    -d "user=<user>&password=<password>"'

Download via the previously saved cookie. Follow any redirect.

curl --cookie cookie.txt --location \
    "" -O 

Other HTTP POST alternatives:

curl -v <url> -d @data_post.txt
w3m -post data_post.txt <url>

Questions, comments? Connect.