Check if a Server is online

Hallo,
can I check somehow with a lua Script if my secound Server is online?
Something like pinging the IP adress of it?

Greetings

You can use a common webhost to send POST updates and fetch the results from other servers. Otherwise, you’ll have to use a socketting module like gsock or bromsock.

Well, you could always use the Steam Web API to return the JSON data for the second server. (Hopefully this is accurate and constantly updated, although I have no idea)

Maybe something like this?



local _IP = "149.56.67.156";
local _Port = "27015";
http.Fetch( "http://api.steampowered.com/ISteamApps/GetServersAtAddress/v0001?addr=" .. _IP .. ":" .. _Port .. "&format=json",
	function( body, len, headers, code )
             local __ServerInfo = util.JSONToTable( body );

             if ( __ServerInfo["response"]["servers"][1]["addr"] != nil ) then --wtf am I doing here
                     print( "SERVER IS ONLINE YAY!" );
             else
                    print( "server is ded" );
              end
	end,
	function( error )
		print("Uh oh. Is Steam API offline?");
		print("Steam API returned error
" .. error );
	end
 )


Untested. So if you get the chance, please let me know!

Didn’t know about that solution, but it is reliant on Steam servers being up which is a moderate con of that alternative.

Thanks alot!
I tried it with my server ip and it works!
However when i try it with a wrong ip address then it throws a error in the console

[ERROR] addons/darkaddon/lua/ulx/modules/sh/darkcmds.lua:144: attempt to index a nil value

  1. onsuccess - addons/darkaddon/lua/ulx/modules/sh/darkcmds.lua:144
  2. unknown - lua/includes/modules/http.lua:34

The 144 line is:
if ( __ServerInfo[“response”][“servers”][1][“addr”] != nil ) then

So i changed it to:
if ( __ServerInfo[“response”][“servers”][1] != nil ) then

And now it is working perfectly.
Thanks alot!