Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always getting 54320 as external port #9

Open
frostwire opened this issue Oct 21, 2014 · 1 comment
Open

always getting 54320 as external port #9

frostwire opened this issue Oct 21, 2014 · 1 comment

Comments

@frostwire
Copy link

is that the expected behavior?

I see that get_ip_info defines 54320 as the default external port, but if I remember correctly, whenever I invoked get_ip_info (about a month ago) I'd get the port the STUN server would see me through, or am I hallucinating?

@liuqun
Copy link

liuqun commented Jan 15, 2018

Hi @frostwire ,
It seems to be buggy:
On my Ubuntu Linux platform I always got external_port=54320.
But on Windows extern_port is a random port number chosen by my router.

We'd better read the source code as the README said.

pystun/README.rst

Lines 82 to 89 in 1191d3d

You may also specify the client interface and port that is used although this
is not needed::
sip = "0.0.0.0" # interface to listen on (all)
port = 54320 # port to listen on
nat_type, external_ip, external_port = stun.get_ip_info(sip, port)
Read the code for more details...

pystun/stun/__init__.py

Lines 246 to 257 in ab5eb34

def get_ip_info(source_ip="0.0.0.0", source_port=54320, stun_host=None,
stun_port=3478):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(2)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((source_ip, source_port))
nat_type, nat = get_nat_type(s, source_ip, source_port,
stun_host=stun_host, stun_port=stun_port)
external_ip = nat['ExternalIP']
external_port = nat['ExternalPort']
s.close()
return (nat_type, external_ip, external_port)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant