Scenario: on the port12345Enable file sharing.8000The port also accesses this share.
According to my previous articleArticle(Http://www.cnblogs.com/MikeZhang/archive/2012/02/11/httpFileSharePythonAndGo.html),
You can easily12345Enable sharing. The effect is as follows:
To implement the desired function, you only need to redirect the port,CodeAs follows:
#!
/usr/bin/python
'''
file:
redirect. PY
author:
Mike
Email:
Mike_Zhang@live.com
'''
Import Socket, OS
Buflen
= 4*1024
Sock1
= Socket. socket (socket. af_inet,
Socket. sock_stream)
Sock1.bind (('192.168.168.100',
8000 ))
Sock1.listen (5)
Sock2
= Socket. socket (socket. af_inet,
Socket. sock_stream)
Sock2.connect (('192.168.168.100',
12345 ))
While True:
Connection, address
= Sock1.accept ()
Buf
= Connection. Recv (buflen)
# Print
Buf
Sock2.send (BUF)
Connection. Send (sock2.recv (buflen ))
Connection. Close ()
Running effect:
Okay, that's all. I hope it will help you.