MENU

Python发送局域网广播

利用Python的broadcast机制发送局域网广播

# -*- coding: utf-8 -*-
import socket


def send(operation):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    port = 9999
    network = '<broadcast>'
    # 发送数据:
    s.sendto(operation.encode("utf-8"), (network, port))

    s.close()


send("open")

文章标题:Python发送局域网广播
如果文中内容侵犯了您的权益,请及时与博主取得联系进行删除!
本站文章未经许可禁止转载,本文地址:https://blog.wanvale.com/archives/221/

Archives QR Code Tip
QR Code for this page
Tipping QR Code