Fix inet_pton PY3

This commit is contained in:
gpotter2 2018-01-15 19:57:03 +01:00
parent 343303a435
commit 3c5f73e4d3
3 changed files with 8 additions and 5 deletions

View File

@ -77,7 +77,7 @@ if six.PY2:
def plain_str(x):
"""Convert basic byte objects to str"""
return x
return x if isinstance(x, basestring) else str(x)
def chb(x):
"""Same than chr() but encode as bytes.
@ -101,7 +101,7 @@ else:
"""Convert basic byte objects to str"""
if isinstance(x, bytes):
return x.decode('utf8')
return x
return x if isinstance(x, str) else str(x)
def chb(x):
"""Same than chr() but encode as bytes.

View File

@ -80,10 +80,8 @@ _INET_PTON = {
def inet_pton(af, addr):
"""Convert an IP address from text representation into binary form."""
# Will replace Net/Net6 objects
if not isinstance(addr, str):
addr = str(addr)
# Use inet_pton if available
addr = plain_str(addr)
# Use inet_pton if available
try:
return socket.inet_pton(af, addr)
except AttributeError:

View File

@ -117,6 +117,11 @@ t.rrname == b'isc.org.' and t.keytag == 12892 and t.algorithm == 5 and t.digestt
= DNSRR(type="TXT") instanciation
t = DNSRR(type="TXT", rdata="test")
= Build DNSRR
an = DNSRR(type='AAAA', rdata='2001::1')
an = DNSRR(raw(an))
assert an.rdata == '2001::1'
= DNSRRR(), check parameters
t = DNSRR(b'\x04test\x00\x00\x10\x00\x01\x00\x00\x00\x00\x018\xffScapy is an interactive packet manipulation program that enables you to sniff, mangle, send network packets ; test equipments ; probe and discover networks ; quickly develop new protocols. It can easily handle most classical tasks like scanning, tracerout7ing, probing, unit tests, attacks or network discovery.')
t.type == 16 and t.rdlen == 312 and t.rdata[:5] == b"Scapy" and t.rdata[-10:] == b"discovery."