#!/usr/bin/env python import os import ipcalc def application(environ, start_response): status = '200 OK' template = """ {title}

Hello, world!

I am website {title}

Accept-Encoding header was set to {acceptencoding}

Available IP range for subnet {subnet} is from {subnet_first} to {subnet_last}

""" subnet = ipcalc.Network('10.128.128.0/24') output = template.format(title=os.environ.get("WEBSITE_NAME", "that nobody set a name for :("), acceptencoding=environ.get("HTTP_ACCEPT_ENCODING"), subnet=str(subnet), subnet_first=subnet.host_first(), subnet_last=subnet.host_last()) response_headers = [('Content-type', 'text/html'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output]