Python Web - Web Server

Card Puncher Data Processing

About

Web - Server in Python

Type

Built-in

  • Python 2: Linux Bash syntax
python -m SimpleHTTPServer 8888 &
  • for Python 3+
python3 -m http.server 8888 &

Socket

import socket

IP_TRANSPARENT = 19

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.IPPROTO_IP, IP_TRANSPARENT, 1)

s.bind(('127.0.0.1', 1234))
s.listen(32)
print("[+] Bound to tcp://127.0.0.1:1234")
while True:
    c, (r_ip, r_port) = s.accept()
    l_ip, l_port = c.getsockname()
    print("[ ] Connection from tcp://%s:%d to tcp://%s:%d" % (r_ip, r_port, l_ip, l_port))
    c.send(b"hello world\n")
    c.close()

After running the server you can connect to it from arbitrary IP addresses with netcat (nc)

nc -v 192.0.2.1 9999
Connection to 192.0.2.1 9999 port [tcp/*] succeeded!
hello world

The server will report the connection indeed was directed to 192.0.2.1 port 9999, even though nobody actually listens on that IP address and port:

sudo python3 server.py
[+] Bound to tcp://127.0.0.1:1234
[ ] Connection from tcp://127.0.0.1:60036 to tcp://192.0.2.1:9999

from: https://blog.cloudflare.com/how-we-built-spectrum/

Others





Discover More
Admanager Homepage
Google Ad Manager - Getting started - How to show your first ad

A page on how to start with Google Ad Manager for a publisher. Got to Ad Manager Create an account if you don't have one (You need to have at minimal an adsense...
Card Puncher Data Processing
Python Web - Web Server Gateway Interface (WSGI)

The Web Server Gateway Interface (WSGI) is a interface that specify how web servers should forward requests to web applications or frameworks. It's written in the Python programming language. A...
Web - Server

A web server is a HTTP server that respond to HTTP request, generally returning a web page (HTML) (but it can serve any type of files). The request is handled: by native handlers (module) (if the server...



Share this page:
Follow us:
Task Runner