Skip to content

Commit

Permalink
Merge 5af0c12 into ab5eb34
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Sinclair committed Oct 4, 2019
2 parents ab5eb34 + 5af0c12 commit a68acaf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
18 changes: 8 additions & 10 deletions stun/__init__.py
Expand Up @@ -88,12 +88,10 @@


def _initialize():
items = dictAttrToVal.items()
for i in range(len(items)):
dictValToAttr.update({items[i][1]: items[i][0]})
items = dictMsgTypeToVal.items()
for i in range(len(items)):
dictValToMsgType.update({items[i][1]: items[i][0]})
for attr, value in dictAttrToVal.items():
dictValToAttr[value] = attr
for msg_type, value in dictMsgTypeToVal.items():
dictValToMsgType[value] = msg_type


def gen_tran_id():
Expand Down Expand Up @@ -133,7 +131,7 @@ def stun_test(sock, host, port, source_ip, source_port, send_data=""):
retVal['Resp'] = False
return retVal
msgtype = binascii.b2a_hex(buf[0:2])
bind_resp_msg = dictValToMsgType[msgtype] == "BindResponseMsg"
bind_resp_msg = dictValToMsgType[int(msgtype)] == "BindResponseMsg"
tranid_match = tranid.upper() == binascii.b2a_hex(buf[4:20]).upper()
if bind_resp_msg and tranid_match:
recvCorr = True
Expand Down Expand Up @@ -191,9 +189,9 @@ def get_nat_type(s, source_ip, source_port, stun_host=None, stun_port=3478):
ret = stun_test(s, stun_host, port, source_ip, source_port)
resp = ret['Resp']
else:
for stun_host in stun_servers_list:
log.debug('Trying STUN host: %s', stun_host)
ret = stun_test(s, stun_host, port, source_ip, source_port)
for stun_server in stun_servers_list:
log.debug('Trying STUN host: %s', stun_server)
ret = stun_test(s, stun_server, port, source_ip, source_port)
resp = ret['Resp']
if resp:
break
Expand Down
1 change: 1 addition & 0 deletions stun/cli.py
Expand Up @@ -60,5 +60,6 @@ def main():
except KeyboardInterrupt:
sys.exit()


if __name__ == '__main__':
main()

0 comments on commit a68acaf

Please sign in to comment.