Last active
July 21, 2021 06:14
-
-
Save kotovalexarian/16ef09aad43424d42ab4386828d1a0da to your computer and use it in GitHub Desktop.
IPv4 and IPv6 multicast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import socket | |
GROUP = '224.1.1.1' | |
HOST = '0.0.0.0' | |
PORT = 5000 | |
def main(): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
sock.bind((GROUP, PORT)) | |
sock.setsockopt(socket.SOL_IP, socket.IP_ADD_MEMBERSHIP, socket.inet_aton(GROUP) + socket.inet_aton(HOST)) | |
while True: | |
data, addr = sock.recvfrom(1024) | |
print(addr, data) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import socket | |
from time import sleep | |
GROUP = '224.1.1.1' | |
PORT = 5000 | |
def main(): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
index = 0 | |
while True: | |
msg = b'message %d' % index | |
print(msg) | |
sock.sendto(msg, (GROUP, PORT)) | |
index += 1 | |
sleep(1) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import socket | |
import struct | |
GROUP = 'ff05::1:1000' | |
PORT = 5000 | |
def main(): | |
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
sock.bind((GROUP, PORT)) | |
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, struct.pack('16si', socket.inet_pton(socket.AF_INET6, GROUP), 0)) | |
while True: | |
data, addr = sock.recvfrom(1024) | |
print(addr, data) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import socket | |
from time import sleep | |
GROUP = 'ff05::1:1000' | |
PORT = 5000 | |
def main(): | |
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
index = 0 | |
while True: | |
msg = b'message %d' % index | |
print(msg) | |
sock.sendto(msg, (GROUP, PORT)) | |
index += 1 | |
sleep(1) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.altlinux.org/Static_Multicast_Routing