Giter Club home page Giter Club logo

Comments (4)

urda avatar urda commented on August 14, 2024

... I didn't even know you could do this with a Minecraft server! This is amazing!

from mcstatus.

Dinnerbone avatar Dinnerbone commented on August 14, 2024

I have to make a generic "address to host,port", so this could fit into that easily. The normal route of "I have a host and a port" doesn't make sense for this, as it'd effectively go out of its way to try and ignore the port you provide.

from mcstatus.

urda avatar urda commented on August 14, 2024

I was thinking about this today, and one way would be to use something like dnspython in the script and make the call from there.

Here's an example python block that can determine the SRV details:

#!/usr/bin/env python

import dns.resolver

host = "some.minecraft.server.com"
srv_request = "_minecraft._tcp"

request = srv_request + "." + host

try:
    answers = dns.resolver.query(request, 'SRV')
except dns.resolver.NXDOMAIN:
    print "NXDOMAIN: the query name does not exist"
except dns.resolver.YXDOMAIN:
    print "YXDOMAIN: the query name is too long after DNAME substitution"
except dns.resolver.NoAnswer:
    print "NoAnswer: the response did not contain an answer"
except dns.resolver.NoNameservers:
    print "NoNameservers: no non-broken nameservers " + \
        "are available to answer the question"
except dns.resolver.Timeout:
    print "Timeout: no answers could be found in the specified lifetime"

try:
    answers
except NameError:
    print "No SRV records found for {0}".format(request)
else:
    for idx, answer in enumerate(answers):
        print "=============== Result {0} ===============".format(idx)
        print "SRV Request .... {0}".format(request)
        print "SRV Port ....... {0}".format(answer.port)
        print "SRV Priority ... {0}".format(answer.priority)
        print "SRV Weight ..... {0}".format(answer.weight)

Which produces this output:

$ python sample.py 
=============== Result 0 ===============
SRV Request .... _minecraft._tcp.some.minecraft.server.com
SRV Port ....... 25565
SRV Priority ... 0
SRV Weight ..... 5

If that was a real SRV record.

Pros:

  • That was easy and fast!

Cons:

  • You will need dnspython to be installed or kept with the script

from mcstatus.

Dinnerbone avatar Dinnerbone commented on August 14, 2024

I added a MinecraftServer.lookup("host:port") method for looking up based on arbitrary user input. This includes parsing host/port and SRV lookups if a port was not defined.

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.