|

楼主 |
发表于 2025-7-9 00:32:18
|
显示全部楼层
江苏省苏州市
import socket
def discover_devices():
print("发现门禁设备")
devices = {}
print("创建设备套接字")
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.settimeout(5)
sock.bind(('0.0.0.0', 7000))
print("发送广播请求")
sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sender.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sender.sendto(b"discover acs all", ('255.255.255.255', 6000))
sender.close()
print("接收设备回应")
while True:
try:
data, addr = sock.recvfrom(1024)
if b'alive' in data:
ip = addr[0]
ident = data.split(b'alive ')[1].decode().strip()
if ip not in devices:
devices[ip] = ident
except socket.timeout:
break
sock.close()
return devices
# 执行设备发现并显示结果
devices = discover_devices()
print("设备发现结果:")
for ip, ident in devices.items():
print(f"IP地址: {ip}, 设备标识: {ident}")
我已经成功用PY实现了,可是易语言代码怎么写呢,有大神吗 |
|