getServerIp | Multi Theft Auto: Wiki Skip to content

getServerIp

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function returns the IP of the server the client is currently connected to.

Note

On server-side there is the getServerIpFromMasterServer function, which might return the server IP under certain conditions. You should consider using a third-party service via fetchServerIp (not an MTA function) if the previous function is unreliable for you.

Syntax

string getServerIp ( [ bool includePort = false ] )
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • includePort (default: false): If set to true , the string will include the port of the server at the end of the string, after a colon (:) character.

Returns

  • string: value

A string containing the remote address of the server the client is currently connected to.

Code Examples

shared

This example creates a console command that outputs the server's IP to the chatbox.

function outputServerIp()
outputChatBox("You are currently connected to ".. getServerIp(true))
end
addCommandHandler("serverIp", outputServerIp)