http://www.perlmonks.org?node_id=1050192


in reply to Point me in the right direction - Monitor a Mulicast IP address or stream

Perl can listen on multicast streams easily with IO::Socket::Multicast. There is even an IPv6 version at IO::Socket::Multicast6.

Here is a simple multicast listener example (IPv4-only):

#!/usr/bin/perl use strict; use warnings; use IO::Socket::Multicast; my $sock = IO::Socket::Multicast->new( LocalPort => 7070, ReuseAddr => 1 ) or die "Cannot create client\n";; $sock->mcast_add("239.192.1.1") || die "Cannot set group: $!\n"; my $data; while (1) { $sock->recv($data,1024); my $peer_addr = $sock->peerhost(); my $peer_port = $sock->peerport(); print "($peer_addr:$peer_port): $data\n" }

You can use a select() timer instead of the while loop and if you reach a timeout - send the email.

  • Comment on Re: Point me in the right direction - Monitor a Mulicast IP address or stream
  • Download Code

Replies are listed 'Best First'.
Re^2: Point me in the right direction - Monitor a Mulicast IP address or stream
by PerlSufi (Friar) on Aug 20, 2013 at 14:49 UTC
Re^2: Point me in the right direction - Monitor a Mulicast IP address or stream
by jasonjackal (Initiate) on Aug 20, 2013 at 19:00 UTC
    Thanks everyone for the quick and detailed replies. I will continue to discover and understand these findings.