[ServerUp] New Syntax, Bulk Checking, Limit for multiple Ports

master
Sfan5 2013-01-19 15:14:01 +01:00
parent bb4ef86fa8
commit b9f3e1e223
1 changed files with 55 additions and 23 deletions

View File

@ -13,32 +13,64 @@ def serverup(phenny, input):
if not '.' in arg: if not '.' in arg:
return phenny.reply("Invalid Address") return phenny.reply("Invalid Address")
if ':' in arg: if ':' in arg:
address = arg.split(':')[0] phenny.reply("Note: Syntax changed please use 'example.org 1337' instead of 'example.org:1337'")
try: arg = arg.split(':')[0] + ' ' + arg.split(':')[1]
port = int(arg.split(':')[1]) if ' ' in arg:
except: address = arg.split(' ')[0]
return phenny.reply("Invalid Port") port = arg.split(' ')[1]
if '-' in port or ',' in port:
ports = []
ports_ = port.split(',')
for p in ports_:
if '-' in p:
if len(p.split('-')) != 2:
return phenny.reply("Invalid Port List")
else:
try:
a = int(p.split('-')[0])
except:
return phenny.reply("Invalid Port: %s" % p.split('-')[0])
try:
b = int(p.split('-')[1]) + 1
except:
return phenny.reply("Invalid Port: %s" % p.split('-')[1])
for i in range(a, b):
ports.append(i)
else:
try:
ports.append(int(p))
except:
return phenny.reply("Invalid Port: %s" % p)
else:
try:
ports = [int(port)]
except:
return phenny.reply("Invalid Port: %s" % port)
else: else:
address = arg address = arg
port = 30000 ports = [30000]
try: if len(ports) > 4 and not (input.admin or input.owner): # Owner and Admins of the Bot can bypass the Limit
start = time.time() return phenny.reply("Too many Ports specified")
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for port in ports:
sock.settimeout(2.5) repres = address + ':' + str(port)
buf = "\x4f\x45\x74\x03\x00\x00\x00\x01" try:
sock.sendto(buf, (address, port)) start = time.time()
data, addr = sock.recvfrom(1000) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
if data: sock.settimeout(2.5)
peer_id = data[12:14] buf = "\x4f\x45\x74\x03\x00\x00\x00\x01"
buf = "\x4f\x45\x74\x03" + peer_id + "\x00\x00\x03"
sock.sendto(buf, (address, port)) sock.sendto(buf, (address, port))
sock.close() data, addr = sock.recvfrom(1000)
end = time.time() if data:
phenny.reply("%s is up (%0.3fms)" % (arg,end-start)) peer_id = data[12:14]
else: buf = "\x4f\x45\x74\x03" + peer_id + "\x00\x00\x03"
phenny.reply("%s seems to be down " % arg) sock.sendto(buf, (address, port))
except: sock.close()
phenny.reply("%s seems to be down " % arg) end = time.time()
phenny.reply("%s is up (%0.3fms)" % (repres,end-start))
else:
phenny.reply("%s seems to be down " % repres)
except:
phenny.reply("%s seems to be down " % repres)