Minecraft LAN Advertising

While looking for a way to “announce” a Minecraft server to local players, I found this article written 7 years ago. The included Python script works with a couple of tweaks to make it compatible with Python 3:

import socket
import time

servers = [
        ["motd1", 25565],
        ["motd2", 25566]
]

BROADCAST_IP = "255.255.255.255"
BROADCAST_PORT = 4445

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

print("Broadcasting Minecraft servers to LAN")

while True:
        for server in servers:
                msg = "[MOTD]%s[/MOTD][AD]%d[/AD]" % (server[0], server[1])
                sock.sendto(msg.encode('UTF-8'), (BROADCAST_IP, BROADCAST_PORT))
        time.sleep(1.5)

You only need to change the server array, defined at the top of the file. Save to a file like broadcast_to_lan.py, and run with python3 broadcast_to_lan.py.

Thanks to kebian for the original script!

comments