@@ -476,7 +476,8 @@ def _write_SOCKS5_address(self, addr, file):
476
476
# Well it's not an IP number, so it's probably a DNS name.
477
477
if rdns :
478
478
# Resolve remotely
479
- file .write (b"\x03 " + chr (len (host )).encode () + host .encode ())
479
+ host_bytes = host .encode ('idna' )
480
+ file .write (b"\x03 " + chr (len (host_bytes )).encode () + host_bytes )
480
481
else :
481
482
# Resolve locally
482
483
addr_bytes = socket .inet_aton (socket .gethostbyname (host ))
@@ -533,7 +534,7 @@ def _negotiate_SOCKS4(self, dest_addr, dest_port):
533
534
# NOTE: This is actually an extension to the SOCKS4 protocol
534
535
# called SOCKS4A and may not be supported in all cases.
535
536
if remote_resolve :
536
- writer .write (dest_addr .encode () + b"\x00 " )
537
+ writer .write (dest_addr .encode ('idna' ) + b"\x00 " )
537
538
writer .flush ()
538
539
539
540
# Get the response from the server
@@ -568,8 +569,8 @@ def _negotiate_HTTP(self, dest_addr, dest_port):
568
569
# If we need to resolve locally, we do this now
569
570
addr = dest_addr if rdns else socket .gethostbyname (dest_addr )
570
571
571
- self .sendall (b"CONNECT " + addr .encode () + b":" + str (dest_port ).encode () +
572
- b" HTTP/1.1\r \n " + b"Host: " + dest_addr .encode () + b"\r \n \r \n " )
572
+ self .sendall (b"CONNECT " + addr .encode ('idna' ) + b":" + str (dest_port ).encode () +
573
+ b" HTTP/1.1\r \n " + b"Host: " + dest_addr .encode ('idna' ) + b"\r \n \r \n " )
573
574
574
575
# We just need the first line to check if the connection was successful
575
576
fobj = self .makefile ()
0 commit comments