Browse Source

ipv6 is buggy; revert for now

1.4
clowwindy 13 years ago
parent
commit
f78a0ea298
  1. 2
      README.md
  2. 34
      local.py
  3. 40
      server.py

2
README.md

@ -13,8 +13,6 @@ Put `server.py` on your server. Edit `server.py`, change the following values:
Run `python server.py` on your server. To run it in the background, run `setsid python server.py`. Run `python server.py` on your server. To run it in the background, run `setsid python server.py`.
If you want to listen to IPv6 port, run `python server.py -6`.
Put `local.py` on your client machine. Edit `local.py`, change these values: Put `local.py` on your client machine. Edit `local.py`, change these values:
SERVER your server ip or hostname SERVER your server ip or hostname

34
local.py

@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
SERVER = 'my_server_ip_or_host' SERVER = 'my server ip'
REMOTE_PORT = 8499 REMOTE_PORT = 8499
PORT = 1080 PORT = 1080
KEY = "foobar!" KEY = "foobar!"
@ -34,35 +34,6 @@ import threading
import time import time
import SocketServer import SocketServer
#disable ThreadingTCPServer dns revsere lookup, sometimes it will be slow
socket.getfqdn = lambda x:x
def socket_create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
source_address=None):
"""python 2.7 socket.create_connection"""
host, port = address
err = None
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
sock = None
try:
sock = socket.socket(af, socktype, proto)
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:
sock.settimeout(timeout)
if source_address:
sock.bind(source_address)
sock.connect(sa)
return sock
except socket.error as _:
err = _
if sock is not None:
sock.close()
if err is not None:
raise err
else:
raise socket.error("getaddrinfo returns an empty list")
def get_table(key): def get_table(key):
m = hashlib.md5() m = hashlib.md5()
m.update(key) m.update(key)
@ -124,7 +95,8 @@ class Socks5Server(SocketServer.StreamRequestHandler):
def handle(self): def handle(self):
try: try:
sock = self.connection sock = self.connection
remote = socket_create_connection((SERVER, REMOTE_PORT)) remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
remote.connect((SERVER, REMOTE_PORT))
self.handle_tcp(sock, remote) self.handle_tcp(sock, remote)
except socket.error as e: except socket.error as e:
lock_print('socket error: %s' % str(e)) lock_print('socket error: %s' % str(e))

40
server.py

@ -23,12 +23,6 @@
PORT = 8499 PORT = 8499
KEY = "foobar!" KEY = "foobar!"
try:
import gevent, gevent.monkey
gevent.monkey.patch_all(dns=gevent.version_info[0]>=1)
except ImportError:
gevent = None
import socket import socket
import select import select
import SocketServer import SocketServer
@ -37,35 +31,6 @@ import string
import hashlib import hashlib
import sys import sys
#disable ThreadingTCPServer dns revsere lookup, sometimes it will be slow
socket.getfqdn = lambda x:x
def socket_create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
source_address=None):
"""python 2.7 socket.create_connection"""
host, port = address
err = None
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
sock = None
try:
sock = socket.socket(af, socktype, proto)
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:
sock.settimeout(timeout)
if source_address:
sock.bind(source_address)
sock.connect(sa)
return sock
except socket.error as _:
err = _
if sock is not None:
sock.close()
if err is not None:
raise err
else:
raise socket.error("getaddrinfo returns an empty list")
def get_table(key): def get_table(key):
m = hashlib.md5() m = hashlib.md5()
m.update(key) m.update(key)
@ -126,7 +91,8 @@ class Socks5Server(SocketServer.StreamRequestHandler):
reply = "\x05\x00\x00\x01" reply = "\x05\x00\x00\x01"
try: try:
if mode == 1: if mode == 1:
remote = socket_create_connection((addr, port[0])) remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
remote.connect((addr, port[0]))
local = remote.getsockname() local = remote.getsockname()
reply += socket.inet_aton(local[0]) + struct.pack(">H", reply += socket.inet_aton(local[0]) + struct.pack(">H",
local[1]) local[1])
@ -146,8 +112,6 @@ class Socks5Server(SocketServer.StreamRequestHandler):
def main(): def main():
if '-6' in sys.argv[1:]:
ThreadingTCPServer.address_family = socket.AF_INET6
server = ThreadingTCPServer(('', PORT), Socks5Server) server = ThreadingTCPServer(('', PORT), Socks5Server)
server.allow_reuse_address = True server.allow_reuse_address = True
print "starting server at port %d ..." % PORT print "starting server at port %d ..." % PORT

Loading…
Cancel
Save