Comments (4)
... I didn't even know you could do this with a Minecraft server! This is amazing!
from mcstatus.
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.
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.
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)
- MCSTATUS raw HOT 2
- Can't ping server on Termux HOT 5
- How do I run mcstatus? HOT 1
- status.version does not have a sensible string representation HOT 3
- Drop support for python 3.6
- Decode ISO 8859-1 into UTF-8
- minecrafBedrockServer failing to connect to a server HOT 5
- TypeError: an integer is required (got type NoneType) HOT 2
- Community Chat? HOT 2
- Key existence for COLOR_MAP is not being checked HOT 3
- Complex Description Styles are lacking test coverage HOT 3
- How to get server name / motd ?
- Update click to 8.0.0 HOT 2
- Raising errors on invalid ip requires rewrite of client logic HOT 15
- Support multiple types of formatting for MOTD
- Synchronous operations inside async functions HOT 1
- To replace sync 'dns.resolver.resolve' with `dns.asyncresolver` HOT 1
- UDPAsyncSocketConnection cannot write anything special itself HOT 3
- Unable to use module in a python script HOT 5
- Getting timeout for status.plays.online HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mcstatus.