I want to build a script / small app to retrieve information about game servers, as seen e.g. on battlemetrics.
Take this server for instance: https://www.battlemetrics.com/servers/dayz/10658603 with following IP addresses.
217.146.82.246:2302 (Game Port)
217.146.82.246:27016 (Query Port)
I have a little experience with web apps, mainly django and drf, and pythons requests
module to make http request to API endpoints of these apps.
Naturally I ignorantly tried retrieving info with the requests
module (i tried query and game port)
response = requests.get('https://217.146.82.246:27016/')
which resulted in a timeout:
HTTPSConnectionPool(host='217.146.82.246', port=27016): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7fd7764023d0>, 'Connection to 217.146.82.246 timed out. (connect timeout=None)'))
I tried retrieving information from the provided IP address, and i expected to retrieve a response with a status code. In case the status code would be 200
, i expected to get some data from the server.
Now, i would be happy to get an answer on how to do this, but i'd also appreciate it a lot to get some hints on what i need to learn/understand in order to make this happen, since i am a little stuck.
Things i am wondering:
1.) I assume that using HTTP protocol is the wrong way, and i have read a little bit about that often game servers use UDP instead of TCP. As I understand HTTP mostly uses TCP as underlying transport layer protocol, however UDP can also be used. Should i use UDP? If so, which application layer protocol should be used? Is there a python module for this?
2.) Given an IP address, is there a way to find out which transport layer protocol, and which application layer protocol this IP address needs to communicate with?
3.) Are my assumptions maybe completely wrong, and just need to understand how to correctly setup requests
for this case (starting a session, providing headers, etc..)?
Thanks in advance for any help!
1.) I assume that using HTTP protocol is the wrong way, and i have read a little bit about that often game servers use UDP instead of TCP. As I understand HTTP mostly uses TCP as underlying transport layer protocol, however UDP can also be used. Should i use UDP? If so, which application layer protocol should be used? Is there a python module for this?
Network is conceptually quite simple: you send bytes, you receive bytes. And so there's no way to know a priori how to interpret those bytes. Clients and servers just agree behind the scenes (i.e. are implemented in such way) on what protocol to use, whether it is http or something else.
A server can implement literally any protocol that you can even imagine. Many game servers implement custom protocols. The only way to understand that is when you have documentation available or maybe by contacting the game devs. Other than that you would have to do reverse engineering, and very likely you will fail at that, assuming it is something different than http.
2.) Given an IP address, is there a way to find out which transport layer protocol, and which application layer protocol this IP address needs to communicate with?
Not really. The timeout you see is likely due to the fact that there is no tcp listener on the other side (or it is behind a firewall). Because the requests
library I believe still uses tcp (even though new http3 is built on top of udp). Which suggests it is a udp endpoint. Or that there is no listener at all. This much you can deduce. Which is not much.
Detecting an application protocol is pretty much impossible. You can try few popular ones (http, ftp, ssh, or something) but there is no guarantee. It is even harder for udp, because there aren't many popular udp protocols out there.
3.) Are my assumptions maybe completely wrong, and just need to understand how to correctly setup requests for this case (starting a session, providing headers, etc..)?
What I suggest is: try to search for the documentation and/or contact the game devs. If that doesn't help then just give up. Even if it is http, then you still need to know path (url), you need to know how to add query parameters and/or body potentially, you need to understand how to interpret response, and to make things more difficult, many http servers use custom mandatory headers. All of that will be hard to figure out without documentation.
I want to build a script / small app to retrieve information about game servers, as seen e.g. on battlemetrics.
It is likely that whoever wrote this battlemetrics thingy already did the research and found out how to communicate with those servers. You can ask them as well.