async def on_message(message): if not message.author.bot == 1: if message.content.upper() == "!MC" or message.content.upper( ) == "!FTB": ms = minestat.MineStat('genco.me', 25565) if ms.online: ms.version = yaziDuzelt(str(ms.version)) ms.current_players = yaziDuzelt(str(ms.current_players)) ms.max_players = yaziDuzelt(str(ms.max_players)) if str(ms.version) == "1102": ms.version = "1.10.2" embed = discord.Embed(title=" ", color=0x75df00) embed.set_author(name="genco.me Server Durumu", icon_url=mcIconURL) embed.add_field(name="Online :", value="✅Evet", inline=True) embed.add_field(name="Versiyon :", value=str(ms.version), inline=True) embed.add_field(name="Oyuncu Sayısı :", value=str(ms.current_players) + " / " + str(ms.max_players), inline=False) await client.send_message(message.channel, embed=embed) else: embed = discord.Embed(title=" ", color=0x75df00) embed.set_author(name="genco.me Server Durumu", icon_url=mcIconURL) embed.add_field(name="Online :", value="❌Hayır", inline=True) await client.send_message(message.channel, embed=embed)
for path in os.listdir(minecraft_path): target = os.path.join(minecraft_path, path, filename) if os.path.isfile( target): # make sure it's a file, not a directory entry with open(target) as f: # open file for line in f: # process line by line if 'server-ip' in line: # search for string #print (found string %s in file %s' % ( line, target )) address = line.split('=')[1].rstrip() if 'server-port' in line: #print ('found string %s in file %s' % ( line, target )) port = line.split('=')[1].rstrip() servers.append([str(address or '0.0.0.0'), int(port)]) # print(servers) # print("Broadcasting Minecraft servers to LAN") for server in servers: ms = minestat.MineStat(server[0], server[1]) if ms.online: msg = "[MOTD]%s[/MOTD][AD]%s[/AD]" % (ms.motd, ms.port) print("advertising " + msg) print( 'Server is online running version %s with %s out of %s players.' % (ms.version, ms.current_players, ms.max_players)) sock.sendto(msg.encode(), (BROADCAST_IP, BROADCAST_PORT)) #else: # print( server[0] + ':' + str(server[1]) + " is Offline, Skipping") time.sleep(5)
import minestat # Below is an example using the MineStat class. # If server is offline, other instance members will be None. ms = minestat.MineStat('minecraft.frag.land', 25565) print('Minecraft server status of %s on port %d:' % (ms.address, ms.port)) if ms.online: print('Server is online running version %s with %s out of %s players.' % (ms.version, ms.current_players, ms.max_players)) print('Message of the day: %s' % ms.motd) print('Message of the day without formatting: %s' % ms.stripped_motd) print('Latency: %sms' % ms.latency) print('Connected using protocol: %s' % ms.slp_protocol) else: print('Server is offline!')
import minestat # Below is an example using the MineStat class. # If server is offline, other instance members will be None. ms = minestat.MineStat('minecraft.dilley.me', 25565) print('Minecraft server status of %s on port %d:' % (ms.address, ms.port)) if ms.online: print('Server is online running version %s with %s out of %s players.' % (ms.version, ms.current_players, ms.max_players)) print('Message of the day: %s' % ms.motd) print('Latency: %sms' % ms.latency) else: print('Server is offline!')
import minestat import smtplib import credentials ipAdd = '' #Enter in the external IP of your server ms = minestat.MineStat(ipAdd, 25565) #If you're using a different port, you would change this here #You can also add email credentials directly if you wish, but importing from a different file adds an extra layer of security user = credentials.user passwd = credentials.passwd print('Minecraft server status of %s on port %d:' % (ms.address, ms.port)) if ms.online: print('Server is online running version %s with %s out of %s players.' % (ms.version, ms.current_players, ms.max_players)) print('Message of the day: %s' % ms.motd) else: print('Server is offline!') contacts = open('numbers.txt').readlines() content = "The Minecraft server is down. " # setting up auto generated emails when server is down mail = smtplib.SMTP('smtp.gmail.com',587) #Accessing the extended smtp stuff mail.ehlo() #Encrypt login credentials mail.starttls() #login to email mail.login(user,passwd) #actual email write mail.sendmail('fromemail',contacts,content) #closing out the login info
import minestat import threading import os import datetime # Below is an example using the MineStat class. # If server is offline, other instance members will be None. ms = minestat.MineStat('34.70.21.148', 25565) def print_status(ms): ms.check_status() cst = datetime.datetime.now() print('Minecraft server status of %s on port %d:' % (ms.address, ms.port)) print('Minecraft server status is %s' % (ms.online)) if ms.online: if ms.current_players == 0 and cst.hour <= 12: print('Minecraft server is closing') os.system("sudo ./stop.sh") else: if cst.hour >= 12: print('Minecraft server is starting') os.system("sudo ./open.sh") threading.Timer(30, print_status, args=(ms, )).start() print_status(ms)
def status(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: with timeout(1, exception=RuntimeError): logger.info("Pinging the server to check if it's online...") sock.connect((secrets.LOCAL_IP, 5555)) logger.info("Ping successful. The server is on.") pass sock.close() try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) with timeout(1, exception=RuntimeError): logger.info("Pinging the server to check if it's online...") sock.connect((secrets.LOCAL_IP, 25565)) logger.info("Ping successful. The server is on.") pass ms = minestat.MineStat('tech189.duckdns.org', 25565) ms1 = 'Online ✅\nVersion %s - %s out of %s players\nLatency: %sms\nPort: 25565' % ( ms.version, ms.current_players, ms.max_players, ms.latency) except RuntimeError: ms1 = 'Offline' sock.close() try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) with timeout(1, exception=RuntimeError): logger.info("Pinging the server to check if it's online...") sock.connect((secrets.LOCAL_IP, 25566)) logger.info("Ping successful. The server is on.") pass sock.close() ms = minestat.MineStat('tech189.duckdns.org', 25566) ms2 = 'Online ✅\nVersion %s - %s out of %s players\nLatency: %sms\nModpack: %s\nPort: 25566' % ( ms.version, ms.current_players, ms.max_players, ms.latency, ms.motd.decode("utf-8")) except RuntimeError: ms2 = 'Offline' zmq_context = zmq.Context() zmq_socket = zmq_context.socket(zmq.REQ) zmq_socket.setsockopt( zmq.LINGER, 0 ) # The default value is -1, which means wait until all messages have been sent before allowing termination. Set to 0 to discard unsent messages immediately, and any positive integer will be the number of milliseconds to keep trying to send before discard. try: with timeout(5, exception=RuntimeError): logger.info("Attempting to connect to the control server...") zmq_socket.connect("tcp://" + secrets.LOCAL_IP + ":5555") logger.info("Connected. Sending \"stats\" command...") zmq_socket.send_string("stats") pass logger.info("Done. Waiting for response...") stats = ast.literal_eval(zmq_socket.recv_string()) except RuntimeError: stats = {'cpu_temp': '???'} return { "result": "Online ✅", "ms1": ms1, "ms2": ms2, "stats": stats } except RuntimeError: logger.info("No response within 1 second. Therefore server is off") return { "result": "Offline", "ms1": 'Offline', "ms2": 'Offline', "stats": { 'cpu_temp': '???' } } sock.close()