nskinkel / oppy

A Tor client (onion proxy) implementation in Python
BSD 3-Clause "New" or "Revised" License
24 stars 3 forks source link

socks.py - `SOCKSProtocol._sendReply()` #13

Closed dwtj closed 10 years ago

dwtj commented 10 years ago

SOCKSProtocol._sendReply() is unfinished.

Are there some standard helper functions for converting from IPv4 strings to a bytes object?

nskinkel commented 10 years ago

Yes. If you mean what I think you mean, you'll want something like this using the ipaddress module (Python 3 only -- Python 2 requires some stuff from pip):

>>> import ipaddress
>>> ipaddress.ip_address('127.0.0.1').packed
b'\x7f\x00x00\x01'

That is, an IPv{4,6}Address object has a packed attribute that is defined as:

The binary representation of this address - a bytes object of the appropriate length (most significant octet first). This is 4 bytes for IPv4 and 16 bytes for IPv6.

dwtj commented 10 years ago

Thanks Nik, that's just what I needed.

Issue closed with 102ae62