This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
chocominer/rng/rng.py

32 lines
712 B
Python

from flask import Flask, Response
import os
import socket
import time
app = Flask(__name__)
# Enable debugging if the DEBUG environment variable is set and starts with Y
app.debug = os.environ.get("DEBUG", "").lower().startswith('y')
hostname = socket.gethostname()
urandom = os.open("/dev/urandom", os.O_RDONLY)
@app.route("/")
def index():
return "RNG running on {}\n".format(hostname)
@app.route("/<int:how_many_bytes>")
def rng(how_many_bytes):
# Simulate a little bit of delay
time.sleep(0.1)
return Response(
os.read(urandom, how_many_bytes),
content_type="application/octet-stream")
if __name__ == "__main__":
app.run(host="0.0.0.0", port=80, threaded=False)