Due to firewall restriction, I have to "share" the 80/tcp port on a machine.
I try to achieve this :
- Python script (or xinetd using a python script) listening on port 80
- Custom (binary language) service listening on port 5000
- When a user try to connect to the port 80 via http browser, it answers code 301 Moved permanently (to https://...)
- When a program tries to connect to port 80, it forwards to port 5000, and then forwards answer to program.
It seems simple but I do not manage to do it.
#!/usr/bin/python
import sys
def file_put_contents(filename, mode, data):
file = open(filename, mode)
file.write(data)
file.close()
pipe = ??
for line in sys.stdin:
if 'GET /' in line:
print 'HTTP/1.1 301 Moved Permanently';
print 'Location: http://www.zyve.com';
else:
file_put_contents(pipe, 'a+', line)
sys.exit(0)
I am new to python, sorry.
Have a nice day,