Updated missing dependancy in requirements.txt and fixed speed issues in SRV lookups for mcping
This commit is contained in:
parent
50195ba8cd
commit
cf7658d28e
2 changed files with 22 additions and 10 deletions
|
@ -3,6 +3,7 @@ import socket
|
||||||
import json
|
import json
|
||||||
import struct
|
import struct
|
||||||
import DNS ## Please remember to install the dependancy 'pydns'
|
import DNS ## Please remember to install the dependancy 'pydns'
|
||||||
|
import time
|
||||||
|
|
||||||
def mccolorconvert(motd):
|
def mccolorconvert(motd):
|
||||||
empty = ""
|
empty = ""
|
||||||
|
@ -44,9 +45,11 @@ def mcping_connect(host, port):
|
||||||
", is it up? Double-check your address!"
|
", is it up? Double-check your address!"
|
||||||
|
|
||||||
def srvData(domain):
|
def srvData(domain):
|
||||||
|
starttime = time.time()
|
||||||
DNS.ParseResolvConf()
|
DNS.ParseResolvConf()
|
||||||
srv_req = DNS.Request(qtype = 'srv')
|
srv_req = DNS.Request(qtype = 'srv')
|
||||||
srv_result = srv_req.req('_minecraft._tcp.%s' % domain)
|
srv_result = srv_req.req('_minecraft._tcp.%s' % domain)
|
||||||
|
print time.time() - starttime
|
||||||
|
|
||||||
for getsrv in srv_result.answers:
|
for getsrv in srv_result.answers:
|
||||||
if getsrv['typename'] == 'SRV':
|
if getsrv['typename'] == 'SRV':
|
||||||
|
@ -116,20 +119,28 @@ def mcping(inp):
|
||||||
"mcping <server>[:port] - Ping a Minecraft server to check status."
|
"mcping <server>[:port] - Ping a Minecraft server to check status."
|
||||||
inp = inp.strip().split(" ")[0]
|
inp = inp.strip().split(" ")[0]
|
||||||
|
|
||||||
|
|
||||||
if ":" in inp:
|
if ":" in inp:
|
||||||
host, port = inp.split(":", 1)
|
host, port = inp.split(":", 1)
|
||||||
try:
|
try:
|
||||||
port = int(port)
|
port = int(port)
|
||||||
except:
|
except:
|
||||||
return "error: invalid port!"
|
return "error: invalid port!"
|
||||||
else:
|
return mccolorconvert(mcping_connect(host, port))
|
||||||
try:
|
|
||||||
getdata = srvData(inp)
|
|
||||||
host = str(getdata[1])
|
|
||||||
port = int(getdata[0])
|
|
||||||
except:
|
|
||||||
host = inp
|
|
||||||
port = 25565
|
|
||||||
return mccolorconvert(mcping_connect(host, port))
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
host = inp
|
||||||
|
port = 25565
|
||||||
|
rdata = mccolorconvert(mcping_connect(host, port))
|
||||||
|
|
||||||
|
if 'is it up' in rdata:
|
||||||
|
print "Default Down, Checking SRV"
|
||||||
|
getdata = srvData(inp)
|
||||||
|
try:
|
||||||
|
host = str(getdata[1])
|
||||||
|
port = int(getdata[0])
|
||||||
|
return mccolorconvert(mcping_connect(host, port))
|
||||||
|
except:
|
||||||
|
return "Error pinging %s, is it up? Double-check your address!" % inp
|
||||||
|
|
||||||
|
else:
|
||||||
|
return rdata
|
|
@ -2,3 +2,4 @@ BeautifulSoup==3.2.1
|
||||||
lxml==3.1beta1
|
lxml==3.1beta1
|
||||||
pyenchant==1.6.5
|
pyenchant==1.6.5
|
||||||
pydns>=2.3.6
|
pydns>=2.3.6
|
||||||
|
BeautifulSoup4
|
Reference in a new issue