當前位置: 首頁>>代碼示例>>Python>>正文


Python socket.SO_BROADCAST屬性代碼示例

本文整理匯總了Python中socket.SO_BROADCAST屬性的典型用法代碼示例。如果您正苦於以下問題:Python socket.SO_BROADCAST屬性的具體用法?Python socket.SO_BROADCAST怎麽用?Python socket.SO_BROADCAST使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在socket的用法示例。


在下文中一共展示了socket.SO_BROADCAST屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def __init__(self, address='0.0.0.0', broadcast='255.255.255.255'):
        # Prepare a socket
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        sock.bind((address, 0))

        self._socket = sock

        self._listener = ListenerThread(sock, self._handle_packet)
        self._listener.start()

        self._packet_handlers = {}

        self._current_handler_id = 0

        self._broadcast = broadcast 
開發者ID:smarthall,項目名稱:python-lifx-sdk,代碼行數:18,代碼來源:network.py

示例2: __init__

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def __init__(self, device, baud=None, input=True, broadcast=False, source_system=255, source_component=0, use_native=mavutil.default_native):
        self._logger = logging.getLogger(__name__)
        a = device.split(':')
        if len(a) != 2:
            self._logger.critical("UDP ports must be specified as host:port")
            sys.exit(1)
        self.port = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.udp_server = input
        self.broadcast = False
        self.addresses = set()
        if input:
            self.port.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            self.port.bind((a[0], int(a[1])))
        else:
            self.destination_addr = (a[0], int(a[1]))
            if broadcast:
                self.port.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
                self.broadcast = True
        mavutil.set_close_on_exec(self.port.fileno())
        self.port.setblocking(False)
        mavutil.mavfile.__init__(self, self.port.fileno(), device, source_system=source_system, source_component=source_component, input=input, use_native=use_native) 
開發者ID:dronekit,項目名稱:dronekit-python,代碼行數:23,代碼來源:mavlink.py

示例3: send_packet

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def send_packet(secret):
    try:
        broadcast_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        broadcast_socket.bind(('', 0))
        broadcast_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    except Exception as err:
        print "[!] Error creating broadcast socket: %s" % err
        sys.exit(ERROR)
    
    data = "nukemyluks_" + secret
    try:
        broadcast_socket.sendto(data, ('<broadcast>', DEFAULT_PORT))
        
    except Exception as err:
        print "[!] Error sending packet: %s" % err
        sys.exit(ERROR) 
開發者ID:juliocesarfort,項目名稱:nukemyluks,代碼行數:18,代碼來源:client.py

示例4: _setup_connection

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def _setup_connection(self, dstaddr, timeout=None):
        port = randint(10000, 60000)
        af, socktype, proto, _canonname, _sa = socket.getaddrinfo(dstaddr, port, socket.AF_INET, socket.SOCK_DGRAM)[0]
        s = socket.socket(af, socktype, proto)
        has_bind = 1
        for _i in range(0, 10):
            # We try to bind to a port for 10 tries
            try:
                s.bind((INADDR_ANY, randint(10000, 60000)))
                s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
                has_bind = 1
            except socket.error:
                pass
        if not has_bind:
            raise NetBIOSError, ('Cannot bind to a good UDP port', ERRCLASS_OS, errno.EAGAIN)
        self.__sock = s 
開發者ID:joxeankoret,項目名稱:CVE-2017-7494,代碼行數:18,代碼來源:nmb.py

示例5: test_beacon_already_running

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def test_beacon_already_running():
    #
    # NB this one has to run without the beacon fixture
    #
    # Bind a socket on a random port before attempting
    # to start a beacon on that same port.
    #
    port = random.choice(nw0.config.DYNAMIC_PORTS)
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    s.bind(("", port))
    try:
        assert nw0.discovery._beacon is None
        nw0.discovery._start_beacon(port=port)
        assert nw0.discovery._beacon is nw0.discovery._remote_beacon
    finally:
        s.close()
        #
        # Make sure any future beacon use assumes it's not
        # already running.
        #
        nw0.discovery._stop_beacon() 
開發者ID:tjguk,項目名稱:networkzero,代碼行數:24,代碼來源:test_discovery.py

示例6: wake_on_lan

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def wake_on_lan(macaddress):
    """Power on remote computers using Wake On LAN."""
    # Handle MACs with or without separators.
    if len(macaddress) == 12:
        pass
    elif len(macaddress) == 12 + 5:
        sep = macaddress[2]
        macaddress = macaddress.replace(sep, '')
    else:
        raise ValueError('Incorrect MAC address format')

    print("Sending magic packet to", macaddress)
    packet = bytes.fromhex(''.join(['FFFFFFFFFFFF', macaddress * 20]))

    # Broadcast it to the LAN.
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    for brd in get_broadcast_list():
        sock.sendto(packet, (brd, 9)) 
開發者ID:epoptes,項目名稱:epoptes,代碼行數:21,代碼來源:wol.py

示例7: run

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def run(self):
        UDP_IP = "0.0.0.0"
        UDP_PORT = 5108

        sock = socket.socket(socket.AF_INET, # Internet
                             socket.SOCK_DGRAM) # UDP
        sock.bind((UDP_IP, UDP_PORT))

        while (True):
            data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes

            spl = data.split("::")
            if (spl[0] == "0"):
                print "received discovery broadcast"
                s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                s.bind(('', 0))
                s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
                uuid = str(configmanager.uuid)
                pairport = str(configmanager.port)
                hostname = socket.gethostname()
                data = uuid+"::"+hostname+"::"+pairport
                s.sendto(data, (addr[0], UDP_PORT)) 
開發者ID:screenfreeze,項目名稱:deskcon-desktop,代碼行數:24,代碼來源:setupdevice.py

示例8: run

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def run(self):
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        port = str(ui.local_port_stream)
        print(ui.local_ip_stream, '-----ip--', ui.local_port_stream)
        msg = 'this is kawaii-player At: port={} https={} pc_to_pc_casting={} msg={}'.format(
            port, ui.https_media_server, ui.pc_to_pc_casting, ui.broadcast_message)
        msg = bytes(msg , 'utf-8')
        if ui.https_media_server:
            https_val = 'https'
        else:
            https_val = 'http'
        subnet_mask = ui.local_ip_stream.rsplit('.', 1)[0] + '.255'
        notify_msg = '{0}://{1}:{2} started broadcasting. Now Clients can Discover it'.format(
            https_val, ui.local_ip_stream, ui.local_port_stream)
        send_notification(notify_msg)
        print(subnet_mask)
        while ui.broadcast_server:
            s.sendto(msg, (subnet_mask,12345))
            time.sleep(1)
        send_notification('Broadcasting Stopped') 
開發者ID:kanishka-linux,項目名稱:kawaii-player,代碼行數:23,代碼來源:thread_modules.py

示例9: wake_on_lan

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def wake_on_lan(mac_address):
    if len(mac_address) == 12:
        pass
    elif len(mac_address) == 12 + 5:
        sep = mac_address[2]
        mac_address = mac_address.replace(sep, '')
    else:
        raise ValueError('Wrong MAC Address format!')  # (EN) Incorrect MAC format!

    data = ''.join(['FFFFFFFFFFFF', mac_address * 20])
    send_data = ''

    for i in range(0, len(data), 2):
        send_data = ''.join([send_data, struct.pack('B', int(data[i: i + 2], 16))])

    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    s.sendto(send_data, ('<broadcast>', 7)) 
開發者ID:jfomu,項目名稱:EcoLab,代碼行數:20,代碼來源:ecolab.py

示例10: discover

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def discover(match="", timeout=2):
	s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
	s.sendto(ssdpre, (ssdpsrc["ip_address"], ssdpsrc["port"]))
	s.settimeout(timeout)
	responses = []
	print ""
	try:
		while True:
			response = s.recv(1000)
			if match in response:
				print response
				responses.append(response)
	except:
		pass
	return responses 
開發者ID:RussianOtter,項目名稱:networking,代碼行數:18,代碼來源:ap-ro.py

示例11: reboot

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def reboot(timeout=2):
	s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
	s.sendto(exptpack1, (ssdpsrc["ip_address"], ssdpsrc["port"]))
	s.settimeout(timeout)
	s.settimeout(timeout)
	trg = raw_input("\nTarget: ")
	tpg = int(input("Port: "))
	for i in range(4):
		sys.stdout.write("\rSending Reboot Payload" + "." * i)
		time.sleep(0.05)
	print ""
	s.sendto(exptpack1, (trg, tpg))
	try:
		s.connect((str(tpg), int(tpg)))
		time.sleep(0.1)
		s.send(u"`REBOOT`")
		s.close()
		time.sleep(1)
		s.connect((str(tpg), int(tpg)))
	except:
		print "UPnP Device Rebooted"
	s.close() 
開發者ID:RussianOtter,項目名稱:networking,代碼行數:25,代碼來源:ap-ro.py

示例12: __init__

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def __init__(self):
		super().__init__(databaseSchema=self.DATABASE)

		self._devices = dict()
		self._broadcastRoom = ''
		self._broadcastFlag = threading.Event()

		self._broadcastPort = None
		self._broadcastTimer = None

		self._flashThread = None

		self._listenPort = None

		self._broadcastSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
		self._broadcastSocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
		self._broadcastSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

		self._listenSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		self._listenSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
		self._listenSocket.settimeout(2) 
開發者ID:project-alice-assistant,項目名稱:ProjectAlice,代碼行數:23,代碼來源:DeviceManager.py

示例13: discover

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def discover(self, name):
        sock = socket.socket(self.sock_family, socket.SOCK_DGRAM)

        try:
            if self.bcast:
                sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)
            data = brine.dump(("RPYC", "QUERY", (name,)))
            sock.sendto(data, (self.ip, self.port))
            sock.settimeout(self.timeout)

            try:
                data, _ = sock.recvfrom(MAX_DGRAM_SIZE)
            except (socket.error, socket.timeout):
                servers = ()
            else:
                servers = brine.load(data)
        finally:
            sock.close()
        return servers 
開發者ID:krintoxi,項目名稱:NoobSec-Toolkit,代碼行數:21,代碼來源:registry.py

示例14: __init__

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def __init__(self, mac):
        self.session_bytes_sent = 0
        self.session_bytes_recv = 0
        self.source_mac = b"\xff\xff\xff\xff\xff\xff" # put mac of your pc if mikrotik is not responding
        self.dest_mac = mac
        
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        self.sock.bind(('', 0))

        self.buffer = []
        self.work = True
        self.connected = False
        self.rm = threading.Thread(target=self.__recv_manager__)
        self.rm.start()

        self.__send_init__() 
開發者ID:BasuCert,項目名稱:WinboxPoC,代碼行數:19,代碼來源:MACServerExploit.py

示例15: __init__

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_BROADCAST [as 別名]
def __init__(self, own_id, is_client=True):
        self.address = get_ownip()
        self.broadcast = '255.255.255.255'
        self.port = settings.discovery_port
        self.own_id = own_id
        self.mask = IS_CLIENT if is_client else IS_SERVER

        # Create UDP socket
        self.handle = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)

        # Ask operating system to let us do broadcasts from socket
        self.handle.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        if hasattr(socket, 'SO_REUSEPORT'):
            self.handle.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
        else:
            self.handle.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

        # Bind UDP socket to local port so we can receive pings
        self.handle.bind(('', self.port)) 
開發者ID:TUDelft-CNS-ATM,項目名稱:bluesky,代碼行數:21,代碼來源:discovery.py


注:本文中的socket.SO_BROADCAST屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。