ユーザ用ツール

サイト用ツール


サイドバー

目次

ホーム










.

Action disabled: source
knowledge:multicast-linux


Linuxで、マルチキャストの動作確認

Linuxでのマルチキャストの動作確認方法

tcpdumpでマルチキャストパケットの確認

tcpdump -i any -n igmp

IGMPの確認(参加しているIGMPバージョンやグループがわかります。)
またigmp leaveの状況もわかります。

tcpdump -i any -n host 233.x.x.x  and port xxxx
  <- どこから、マルチキャスト受信しているがわかります。

tcpdump -i any -n udp and not port 161   <-  UDP 161(SNMP)以外のUDP全て


自分の参加しているマルチキャストグループを表示

netstat -g


参加しているIGMPのバージョンを確認

cat /proc/net/igmp

マルチキャストのアドレスが追加されます。




Linuxでマルチキャストの送信テストと受信テスト

troglobit/mtools

https://github.com/troglobit/mtools

msend - send UDP messages to a multicast group
mreceive - receive UDP multicast messages and display them

# git clone https://github.com/troglobit/mtools
# cd mtools
# make
# ls
LICENSE.md  README.md  mreceive.8  mreceive.d    mreceive.o  msend.8  msend.d    msend.o
Makefile    mreceive   mreceive.c  mreceive.map  msend       msend.c  msend.map  ttcp.c
# ./mreceive -h
mreceive version 2.3
Usage: mreceive [-g GROUP] [-p PORT] [-i ADDRESS ] ... [-i ADDRESS] [-n]
       mreceive [-v | -h]
 
  -g GROUP     IP multicast group address to listen to.  Default: 224.1.1.1
  -p PORT      UDP port number used in the multicast packets.  Default: 4444
  -i ADDRESS   IP addresses of one or more interfaces to listen for the given
               multicast group.  Default: the system default interface.
  -n           Interpret the contents of the message as a number instead of
               a string of characters.  Use this with `msend -n`
  -v           Print version information.
  -h           Print the command usage.
# ./msend -h
msend version 2.3
Usage:  msend [-g GROUP] [-p PORT] [-join] [-i ADDRESS] [-t TTL] [-P PERIOD]
              [-text "text"|-n]
        msend [-v | -h]
 
  -g GROUP     IP multicast group address to send to.  Default: 224.1.1.1
  -p PORT      UDP port number used in the multicast packets.  Default: 4444
  -i ADDRESS   IP address of the interface to use to send the packets.
               The default is to use the system default interface.
  -join        Multicast sender will join the multicast group.
               By default a sender never joins the group.
  -P PERIOD    Interval in milliseconds between packets.  Default 1000 msec
  -t TTL       The TTL value (1-255) used in the packets.  You must set
               this higher if you want to route the traffic, otherwise
               the first router will drop the packets!  Default: 1
  -text "text" Specify a string to use as payload in the packets, also
               displayed by the mreceive command.  Default: empty
  -n           Encode -text argument as a number instead of a string.
  -v           Print version information.
  -h           Print the command usage.


Pythonでマルチキャストテスト

send_multicast.py

#!/usr/bin/python3

import socket
import time

LOCAL_IP = '192.168.0.30'
MCAST_GRP = '224.1.1.1'
MCAST_PORT = 5007

MULTICAST_TTL = 10

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP, 0)
sock.setsockopt(socket.IPPROTO_IP,
                socket.IP_MULTICAST_TTL,
                MULTICAST_TTL,
                socket.inet_aton(LOCAL_IP))

count = 0
while True:
    message = 'test:{0}'.format(count).encode('utf-8')
    print(message)
    sock.sendto(message, (MCAST_GRP, MCAST_PORT))
    count +=1
    time.sleep(0.5)

rece_multicast.py

#!/usr/bin/python36

import socket
import struct

MCAST_GRP = '224.1.1.1'
MCAST_PORT = 5007
LOCAL_IP = '192.168.0.22'

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((MCAST_GRP, MCAST_PORT))


sock.setsockopt(socket.IPPROTO_IP,
                socket.IP_ADD_MEMBERSHIP,
                socket.inet_aton(MCAST_GRP) + socket.inet_aton(LOCAL_IP))

while True:
  # For Python 3, change next line to "print(sock.recv(10240))"
  #Python3
  print(sock.recv(10240))
  #Python2
  #print sock.recv(10240)


knowledge/multicast-linux.txt · 最終更新: 2021/03/05 23:43 by kurihara

ページ用ツール