Skip to content

Commit

Permalink
Got things working in Python 3 properly!
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Sinclair committed Oct 10, 2019
1 parent 986d8a3 commit 2d724e7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions stun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ def stun_test(sock, host, port, source_ip, source_port, send_data=""):
else:
retVal['Resp'] = False
return retVal
msgtype = binascii.b2a_hex(buf[0:2])
bind_resp_msg = dictValToMsgType[int(msgtype)] == "BindResponseMsg"
tranid_match = tranid.upper() == binascii.b2a_hex(buf[4:20]).upper()
msgtype = binascii.b2a_hex(buf[0:2]).decode()
bind_resp_msg = dictValToMsgType[msgtype] == "BindResponseMsg"
tranid_match = tranid.upper() == binascii.b2a_hex(buf[4:20]).decode().upper()
if bind_resp_msg and tranid_match:
recvCorr = True
retVal['Resp'] = True
len_message = int(binascii.b2a_hex(buf[2:4]), 16)
len_remain = len_message
base = 20
while len_remain:
attr_type = binascii.b2a_hex(buf[base:(base + 2)])
attr_type = binascii.b2a_hex(buf[base:(base + 2)]).decode()
attr_len = int(binascii.b2a_hex(buf[(base + 2):(base + 4)]), 16)
if attr_type == MappedAddress:
port = int(binascii.b2a_hex(buf[base + 6:base + 8]), 16)
Expand Down Expand Up @@ -186,14 +186,17 @@ def get_nat_type(s, source_ip, source_port, stun_host=None, stun_port=3478):
log.debug("Do Test1")
resp = False
if stun_host:
log.debug('Trying STUN host: %s', stun_host)
ret = stun_test(s, stun_host, port, source_ip, source_port)
resp = ret['Resp']
else:
log.debug('Trying all STUN hosts')
for stun_server in stun_servers_list:
log.debug('Trying STUN host: %s', stun_server)
log.debug(' - %s', stun_server)
ret = stun_test(s, stun_server, port, source_ip, source_port)
resp = ret['Resp']
if resp:
stun_host = stun_server
break
if not resp:
return Blocked, ret
Expand Down

0 comments on commit 2d724e7

Please sign in to comment.