Retrieving Public IP and Used Port (serverside)


I’m currently hosting two servers on a dedicated server. For a feature I require to retrieve the public IP and portnumber used for the server-instance the script is executed on.
I have tried the following:

local serverPort = GetConVarNumber("hostport"); -- always returns 27015
local serverIP = GetConVarString("ip"); -- always returns localhost

-- I've also tried the below:
local serverHostIP = GetConVarNumber("hostip"); -- this returns a negative number, I -did- try to use GetConVarString() instead with the same result

But in both instances it returns 27015, I guess that’s the value in the server.cfg. Though, when I launch the second instance of the server it says:

In the above situation I’d like to retrieve the value “27017”.
Also, as seen in the comment in my codesnippet, the ip can’t be found either.
I am confident there is -some- way to get these values, because typing “status” in the console displays me these values…!

Any ideas how this is achieved? I need this because I want the script to be dynamic.

Looking forward to your replies!

A “shameless” little BringUpMyPost here, there should be -someone- who is able to assist me ? :open_mouth:

[lua]http.Get(“”, “”, function(strIP, iLen)
print("My IP is " … strIP)

I don’t know about the hostport though.

Going to give it a try, thanks! Port is the most crucial thing for my set-up though, I mean it -should- be possible somehow!

I don’t think there are any functions to get the port you’re running from. It’s generally a good idea to set the hostport convar to the port you want to run, though, instead of just letting it auto assign to a different port, which can be done in the batch file you use to open the server.

Yep that’s my current work-around! I guess I’ll have to stick to this. :[
Maybe GMod 13 will bring us something like this!