Giter Club home page Giter Club logo

Comments (10)

winny- avatar winny- commented on August 14, 2024 1

By the way since 1.7 the regular server list ping (using the .status() method) includes a limited list of players connected to the server. This should work on all servers without modifying servers.properties to enable the Query proto.

from mcstatus.

winny- avatar winny- commented on August 14, 2024 1

Sure -- you may want to read the official python tutorial, however.

Run it like this:

$ python2 ping_example.py 54.69.165.139
A Minecraft Server (54.69.165.139) v1.8.3 210.007ms 2/20 dummy, blue_calx

#!/usr/bin/env python

from mcstatus.server import MinecraftServer
import sys


def print_status(address):
    server = MinecraftServer(address)
    status = server.status()
    if status.players.sample:
        players_string = ', '.join(p.name for p in status.players.sample)
    else:
        players_string = ''
    print('{0} ({1}) v{2} {3}ms {4}/{5}{6}{7}'.format(
        status.description,
        address,
        status.version.name,
        status.latency,
        status.players.online,
        status.players.max,
        bool(players_string)*' ',  # Only include space if there is data.
        players_string,
    ))


def main():
    for arg in sys.argv[1:]:
        print_status(arg)


if __name__ == '__main__':
    main()

from mcstatus.

ctian1 avatar ctian1 commented on August 14, 2024

Can you paste your script here or on hastebin.com or something?

from mcstatus.

wiihoffmann avatar wiihoffmann commented on August 14, 2024

Right now i'm just trying to get the query feature to work so im using the code supplied on the main page of the repository.
the code i'm using is below and in its entirety (i removed the ip as i shouldn't be giving it out):

from mcstatus import MinecraftServer

If you know the host and port, you may skip this and use MinecraftServer("example.org", 1234)

server = MinecraftServer("i purposely removed the ip")
query = server.query()
print("The server has the following players online: {0}".format(", ".join(query.players.names)))

from mcstatus.

winny- avatar winny- commented on August 14, 2024

Try this server: 54.69.165.139 -- it has the query proto enabled and has a dummy client connected.

It works for me using Python 2.7.6 and mcstatus 2.1 on Windows 7.

from mcstatus.

wiihoffmann avatar wiihoffmann commented on August 14, 2024

Thanks, it would appear that I set something up wrong in the server properties as the ip winny supplied works great. Thank you all for the help

from mcstatus.

wiihoffmann avatar wiihoffmann commented on August 14, 2024

Sorry but i'm rather new to python and as a result i can't get the .status() method of receiving a limited list of names names to work. Would it be possible for someone to leave an example of how to use this method?

from mcstatus.

wiihoffmann avatar wiihoffmann commented on August 14, 2024

Really, bringing an old thread back to life by posting a useless comment?

from mcstatus.

Bunkerbewohner avatar Bunkerbewohner commented on August 14, 2024

I have the same problem using mcstatus 2.1 in a Django app. The problem also occurs when using mcstatus outside of the Django app. I also tested it with Python 2.7, on Windows, and Linux - no difference. It always just times out during the UDP handshake. Maybe related to #37? Any solution?
The minecraft server is version 1.8.8 and I can query it just fine via https://dinnerbone.com/minecraft/tools/status/. Assuming this uses the same code, I don't quite understand the problem.

When I disable my firewall instead of the timeout I receive the following error at the same location:
Exception Value: [WinError 10054] An existing connection was forcibly closed by the remote host

Django Version: 1.8.4
Python Version: 3.5.0
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'mclobby')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:
File "C:\Users\Mathias\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Mathias\PycharmProjects\mclobby\mclobby\views.py" in query
  27.     query = server.query()
File "C:\Users\Mathias\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mcstatus\server.py" in query
  82.             raise exception
File "C:\Users\Mathias\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mcstatus\server.py" in query
  77.                 querier.handshake()
File "C:\Users\Mathias\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mcstatus\querier.py" in handshake
  32.         packet = self._read_packet()
File "C:\Users\Mathias\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mcstatus\querier.py" in _read_packet
  25.         packet.receive(self.connection.read(self.connection.remaining()))
File "C:\Users\Mathias\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mcstatus\protocol\connection.py" in read
  172.             result.extend(self.socket.recvfrom(self.remaining())[0])

Exception Type: timeout at /query
Exception Value: timed out

from mcstatus.

kevinkjt2000 avatar kevinkjt2000 commented on August 14, 2024

@Bunkerbewohner Please create your own issue instead of piggybacking off of someone else's.
Locking this conversation.

from mcstatus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.