mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
support ipv6
This commit is contained in:
parent
d66fd5ba1b
commit
a7ac97eb82
@ -176,12 +176,13 @@ class Reader(_FileLike):
|
||||
class TCPClient:
|
||||
rbufsize = -1
|
||||
wbufsize = -1
|
||||
def __init__(self, host, port, source_address=None):
|
||||
def __init__(self, host, port, source_address=None, use_ipv6=False):
|
||||
self.host, self.port = host, port
|
||||
self.connection, self.rfile, self.wfile = None, None, None
|
||||
self.cert = None
|
||||
self.ssl_established = False
|
||||
self.source_address = source_address
|
||||
self.use_ipv6 = use_ipv6
|
||||
|
||||
def convert_to_ssl(self, cert=None, sni=None, method=TLSv1_METHOD, options=None):
|
||||
"""
|
||||
@ -211,11 +212,10 @@ class TCPClient:
|
||||
|
||||
def connect(self):
|
||||
try:
|
||||
addr = socket.gethostbyname(self.host)
|
||||
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
connection = socket.socket(socket.AF_INET6 if self.use_ipv6 else socket.AF_INET, socket.SOCK_STREAM)
|
||||
if self.source_address:
|
||||
connection.bind(self.source_address)
|
||||
connection.connect((addr, self.port))
|
||||
connection.connect((self.host, self.port))
|
||||
self.rfile = Reader(connection.makefile('rb', self.rbufsize))
|
||||
self.wfile = Writer(connection.makefile('wb', self.wbufsize))
|
||||
except (socket.error, IOError), err:
|
||||
|
Loading…
Reference in New Issue
Block a user