Skip to content

Commit

Permalink
Add source_address support, change IPv6 error
Browse files Browse the repository at this point in the history
  • Loading branch information
Anorov committed Aug 8, 2015
1 parent bbc7258 commit 89f2f97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Example use case with the `sockshandler` urllib2 handler. Note that you must imp
import socks
from sockshandler import SocksiPyHandler

opener = urllib2.build_opener(SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050))
opener = urllib2.build_opener(SocksiPyHandler(socks.SOCKS5, "127.0.0.1", 9050))
print opener.open("http:https://www.somesite.com/") # All requests made by the opener will pass through the SOCKS proxy

--------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
from distutils.core import setup

VERSION = "1.5.4"
VERSION = "1.5.5"

setup(
name = "PySocks",
Expand Down
10 changes: 6 additions & 4 deletions socks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
SocksiPy - Python SOCKS module.
Version 1.5.4
Version 1.5.5
Copyright 2006 Dan-Haim. All rights reserved.
Expand Down Expand Up @@ -52,7 +52,7 @@
-Various small bug fixes
"""

__version__ = "1.5.4"
__version__ = "1.5.5"

import socket
import struct
Expand Down Expand Up @@ -167,6 +167,8 @@ def create_connection(dest_pair, proxy_type=None, proxy_addr=None,
if proxy_type is not None:
sock.set_proxy(proxy_type, proxy_addr, proxy_port, proxy_rdns,
proxy_username, proxy_password)
if source_address is not None:
sock.bind(source_address)
sock.connect(dest_pair)
return sock

Expand Down Expand Up @@ -625,11 +627,11 @@ def connect(self, dest_pair):
dest_pair - 2-tuple of (IP/hostname, port).
"""
if len(dest_pair) != 2:
if len(dest_pair) != 2 or dest_pair[0].startswith("["):
# Probably IPv6, not supported -- raise an error, and hope
# Happy Eyeballs (RFC6555) makes sure at least the IPv4
# connection works...
raise socket.error("SocksPy doesn't support IPv6")
raise socket.error("PySocks doesn't support IPv6")

dest_addr, dest_port = dest_pair

Expand Down

0 comments on commit 89f2f97

Please sign in to comment.