27 lines
637 B
Python
27 lines
637 B
Python
import socket
|
|
|
|
HOST = ''
|
|
PORT = 8000
|
|
|
|
content = b'''HTTP/1.x 200 OK
|
|
'''
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.bind((HOST, PORT))
|
|
|
|
while True:
|
|
s.listen(3)
|
|
conn, addr = s.accept()
|
|
request = conn.recv(4096)
|
|
method = request.decode().split(' ')[0]
|
|
src = request.decode().split(' ')[1]
|
|
body = request.decode().split('\r\n\r\n', 1)[1]
|
|
|
|
if method == 'POST':
|
|
with open('/dev/usb/lp0', 'w') as printer:
|
|
printer.write('\n'+str(addr)+'\n')
|
|
printer.write(str(request)+'\n')
|
|
printer.write('\n'*2+str(body)+'\n')
|
|
conn.sendall(content)
|
|
|
|
conn.close() |