29 lines
672 B
Python
29 lines
672 B
Python
import socket
|
|
|
|
from zeroconf import ServiceInfo, Zeroconf
|
|
|
|
service_type = "_http._tcp.local."
|
|
service_name = "RoomF2703._http._tcp.local."
|
|
server_ip = "192.168.137.1"
|
|
server_port = 5000
|
|
|
|
ip_address = socket.inet_aton(server_ip)
|
|
zeroconf = Zeroconf()
|
|
info = ServiceInfo(
|
|
type_=service_type,
|
|
name=service_name,
|
|
addresses=[ip_address],
|
|
server="RoomF2703.local.",
|
|
port=server_port,
|
|
properties={"path": "/api/endpoints"},
|
|
)
|
|
|
|
zeroconf.register_service(info)
|
|
print(f"Service {service_name} is now discoverable on {server_ip}:{server_port}")
|
|
|
|
try:
|
|
input("Press enter to exit...\n\n")
|
|
finally:
|
|
zeroconf.unregister_service(info)
|
|
zeroconf.close()
|