Skip to content

Request: Get Server IP #155

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

Closed
Frag1337 opened this issue Oct 6, 2016 · 6 comments
Closed

Request: Get Server IP #155

Frag1337 opened this issue Oct 6, 2016 · 6 comments

Comments

@Frag1337
Copy link
Contributor

Frag1337 commented Oct 6, 2016

Hey,

Could you guys add a way to get the current server ip? I don't like the way to hardcode or use the cvar 'hostip' and im already using

from engines.server import server
server_port = server.udp_port

Thanks

@jordanbriere
Copy link
Contributor

What about the ip convar?

from cvars import ConVar

ip = ConVar('ip')
print(ip.get_string())

@Frag1337
Copy link
Contributor Author

Frag1337 commented Oct 6, 2016

@invincibleqc It would probably work, but for which reason is server.udp_port added then? If you could just use "hostport" "hostname" "hostip" etc.

@Ayuto
Copy link
Member

Ayuto commented Oct 6, 2016

It would probably work, but for which reason is server.udp_port added then?

I simply exposed the whole IServer interface. We can certainly add something like get_server_ip, but it would probably just a wrapper for the code posted by @invincibleqc.
Though, that probably makes sense, because not everyone might know about the ip convar.

@jordanbriere
Copy link
Contributor

We could also add a SERVER_ADDRESS constant to the core package or something like that, as well.

@Frag1337
Copy link
Contributor Author

Any news? :)

@Ayuto
Copy link
Member

Ayuto commented Nov 26, 2016

Try this:

from urllib.request import urlopen

def get_public_ip():
    return urlopen('http://ip.42.pl/raw').read().decode()
    
print(get_public_ip())

Ayuto added a commit that referenced this issue Jun 4, 2017
@Ayuto Ayuto closed this as completed Jun 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants