This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
# comments (#) are allowed
# complete empty line are allowed (no spaces)
# ServiceID:MulticastAddress:Port:MulticastInterfaceIP
emdi P A 1:234.56.78.90:45678:192.168.88.110
emdi P A 2:234.56.78.90:45678:192.168.88.110
emdi P A 3:234.56.78.90:45678:192.168.88.110
emdi P A 4:234.56.78.90:45678:192.168.88.110
emdi P B 1:234.56.78.90:45678:192.168.88.110
emdi P B 2:234.56.78.90:45678:192.168.88.110
emdi P B 3:234.56.78.90:45678:192.168.88.110
emdi P B 4:234.56.78.90:45678:192.168.88.110
emdi S A 1:234.56.78.90:45678:192.168.88.110
emdi S A 2:234.56.78.90:45678:192.168.88.110
emdi S A 3:234.56.78.90:45678:192.168.88.110
emdi S A 4:234.56.78.90:45678:192.168.88.110
emdi S B 1:234.56.78.90:45678:192.168.88.110
emdi S B 2:234.56.78.90:45678:192.168.88.110
emdi S B 3:234.56.78.90:45678:192.168.88.110
emdi S B 4:234.56.78.90:45678:192.168.88.110

View File

@@ -0,0 +1,3 @@
1 | 234.56.78.90 | 45678 | 192.168.88.110 | yes | live since Thu Jan 21 15:45:29 2016
1 | 234.56.78.90 | 45678 | 192.168.88.110 | yes | at Thu Jan 21 15:46:12 2016 down for 29 seconds
1 | 234.56.78.90 | 45678 | 192.168.88.110 | yes | live since Thu Jan 21 15:46:26 2016

View File

@@ -0,0 +1,114 @@
#!/usr/bin/perl
$|=1;
use Thread;
use IO::Socket::Multicast;
#use Win32::Console::ANSI qw /Cursor Title/;
#use Term::ANSIScreen qw /:screen :cursor/;
use strict;
my %mcasts :shared;
my %mcdata :shared;
my %mcopen :shared;
my %stream :shared;
my $thr;
my $TimeOut = 30;
my $starttime;
my $lastdown;
my $lastdowns;
# Konfigdatei einlesen
open CONF, "<$0.conf";
my @config=<CONF>;
close CONF;
foreach (@config) {
chomp;
next if ($_ =~ /^#/);
next if (length($_)==0);
$mcasts{$_}='';
}
# Threads für die einzelnen Multicastgruppen anstarten
foreach (keys %mcasts) { $thr = new Thread (\&WaitForMessage,$_); }
# Startzeit, lesbar
my $t=localtime;
# startzeit, als fortlaufende zahl
$starttime = time;
# Anzeige aufbauen
while (1) {
print "\e[2J\n";
#aktuelle zeit, als fortlaufende zahl
my $atime=time;
printf "program runs since %s (for %d seconds)\n\n", $t, $atime-$starttime;
printf "%7s | %15s | %5s | %15s | %s | %s\n", "SESSION", "MCAST Grp", "Port", "Interface", "Open", "Last Data";
open LOG, ">>$0.log";
foreach (sort keys %mcasts) {
my ($session,$IP,$PORT,$IF)=split /:/,$_;
my $open="no";
$open="yes" if ($mcopen{$_} == 1);
if ($mcdata{$_} eq "") {
printf "%7d | %15s | %5s | %15s | %4s | %s\n", $session, $IP, $PORT, $IF, $open, 'NEVER';
}
else {
if ($atime-$mcasts{$_} > $TimeOut) {
printf "%7d | %15s | %5s | %15s | %4s | more than %d sec ago\n", $session, $IP, $PORT, $IF, $open, $TimeOut;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime;
$lastdown=localtime;
$lastdowns=$session;
if ($hour>=7 and $hour<=19) {
if ($stream{$_} == 1) {
#printf LOG "%s\n", scalar localtime;
printf LOG "%7d | %15s | %5s | %15s | %4s | at %s down for %d seconds\n", $session, $IP, $PORT, $IF, $open, scalar localtime, $TimeOut-1;
}
$stream{$_}=0;
}
}
else {
printf "%7d | %15s | %5s | %15s | %4s | %d seconds ago\n", $session, $IP, $PORT, $IF, $open, $atime-$mcasts{$_};
if ($stream{$_} == 0) {
#printf LOG "%s\n", scalar localtime;
printf LOG "%7d | %15s | %5s | %15s | %4s | live since %s\n", $session, $IP, $PORT, $IF, $open, scalar localtime;
}
$stream{$_}=1;
}
}
}
close LOG;
printf "\nLetzter Fehler: Session $lastdowns am $lastdown\n" if ($lastdowns ne "");
printf "\nKein Fehler seit Programmstart aufgetreten\n" if ($lastdowns eq "");
printf "\nv1.6 by Andre Geißler\n";
sleep 1;
}
close LOG;
# Baut Sockets für Multicast Empfang auf und sichert die zuletzt empfangenen Daten und dazu einen Zeitstempel
sub WaitForMessage {
my ($IPPORT)=@_;
my ($SESSION, $IP, $PORT, $IF) = split/:/,$IPPORT;
my $sock;
$mcopen{$IPPORT}=0;
while (!$sock) {
$sock = IO::Socket::Multicast->new(LocalPort=>$PORT,ReuseAddr=>1);
sleep 1;
}
$sock->mcast_add($IP, $IF);
$mcopen{$IPPORT}=1;
my $data;
while (1) {
$sock->recv($data,512);
$mcdata{$IPPORT}="DATA received in the last $TimeOut seconds"; #$data;
$mcasts{$IPPORT}=time;
}
}

View File

@@ -0,0 +1,115 @@
#!/usr/bin/perl
$|=1;
use Thread;
use IO::Socket::Multicast;
#use Win32::Console::ANSI qw /Cursor Title/;
#use Term::ANSIScreen qw /:screen :cursor/;
use strict;
my %mcasts :shared;
my %mcdata :shared;
my %mcopen :shared;
my %stream :shared;
my $thr;
my $TimeOut = 30;
my $starttime;
my $lastdown;
my $lastdowns;
# Konfigdatei einlesen
open CONF, "<$0.conf";
my @config=<CONF>;
close CONF;
foreach (@config) {
chomp;
next if ($_ =~ /^#/);
next if (length($_)==0);
$_ =~ s/\r//g;
$mcasts{$_}='';
}
# Threads für die einzelnen Multicastgruppen anstarten
foreach (keys %mcasts) { $thr = new Thread (\&WaitForMessage,$_); }
# Startzeit, lesbar
my $t=localtime;
# startzeit, als fortlaufende zahl
$starttime = time;
# Anzeige aufbauen
while (1) {
print "\e[2J\n";
#aktuelle zeit, als fortlaufende zahl
my $atime=time;
printf "program runs since %s (for %d seconds)\n\n", $t, $atime-$starttime;
printf "%7s | %15s | %5s | %15s | %s | %s\n", "SESSION", "MCAST Grp", "Port", "Interface", "Open", "Last Data";
open LOG, ">>$0.log";
foreach (sort keys %mcasts) {
my ($session,$IP,$PORT,$IF)=split /:/,$_;
my $open="no";
$open="yes" if ($mcopen{$_} == 1);
if ($mcdata{$_} eq "") {
printf "%7d | %15s | %5s | %15s | %4s | %s\n", $session, $IP, $PORT, $IF, $open, 'NEVER';
}
else {
if ($atime-$mcasts{$_} > $TimeOut) {
printf "%7d | %15s | %5s | %15s | %4s | more than %d sec ago\n", $session, $IP, $PORT, $IF, $open, $TimeOut;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime;
$lastdown=localtime;
$lastdowns=$session;
if ($hour>=7 and $hour<=19) {
if ($stream{$_} == 1) {
#printf LOG "%s\n", scalar localtime;
printf LOG "%7d | %15s | %5s | %15s | %4s | at %s down for %d seconds\n", $session, $IP, $PORT, $IF, $open, scalar localtime, $TimeOut-1;
}
$stream{$_}=0;
}
}
else {
printf "%7d | %15s | %5s | %15s | %4s | %d seconds ago\n", $session, $IP, $PORT, $IF, $open, $atime-$mcasts{$_};
if ($stream{$_} == 0) {
#printf LOG "%s\n", scalar localtime;
printf LOG "%7d | %15s | %5s | %15s | %4s | live since %s\n", $session, $IP, $PORT, $IF, $open, scalar localtime;
}
$stream{$_}=1;
}
}
}
close LOG;
printf "\nLetzter Fehler: Session $lastdowns am $lastdown\n" if ($lastdowns ne "");
printf "\nKein Fehler seit Programmstart aufgetreten\n" if ($lastdowns eq "");
printf "\nv1.7 by Andre Geissler\n";
sleep 1;
}
close LOG;
# Baut Sockets für Multicast Empfang auf und sichert die zuletzt empfangenen Daten und dazu einen Zeitstempel
sub WaitForMessage {
my ($IPPORT)=@_;
my ($SESSION, $IP, $PORT, $IF) = split/:/,$IPPORT;
my $sock;
$mcopen{$IPPORT}=0;
while (!$sock) {
$sock = IO::Socket::Multicast->new(LocalPort=>$PORT,ReuseAddr=>1);
sleep 1;
}
$sock->mcast_add($IP, $IF);
$mcopen{$IPPORT}=1;
my $data;
while (1) {
$sock->recv($data,16);
$mcdata{$IPPORT}="DATA received in the last $TimeOut seconds"; #$data;
$mcasts{$IPPORT}=time;
}
}

View File

@@ -0,0 +1,118 @@
#!/usr/bin/perl
$|=1;
use Thread;
use IO::Socket::Multicast;
#use Win32::Console::ANSI qw /Cursor Title/;
#use Term::ANSIScreen qw /:screen :cursor/;
use strict;
my %mcasts :shared;
my %mcdata :shared;
my %mcopen :shared;
my %stream :shared;
my $thr;
my $TimeOut = 10;
my $starttime;
my $lastdown;
my $lastdowns;
# Konfigdatei einlesen
open CONF, "<$0.conf";
my @config=<CONF>;
close CONF;
foreach (@config) {
chomp;
next if ($_ =~ /^#/);
next if (length($_)==0);
$_ =~ s/\r//g;
$mcasts{$_}='';
}
# Threads für die einzelnen Multicastgruppen anstarten
foreach (keys %mcasts) { $thr = new Thread (\&WaitForMessage,$_); }
# Startzeit, lesbar
my $t=localtime;
# startzeit, als fortlaufende zahl
$starttime = time;
# Anzeige aufbauen
open LOG, ">$0.log";
printf LOG "%7s | %15s | %5s | %15s | %s | %s\n", "SESSION", "MCAST Grp", "Port", "Interface", "Open", "Last Data";
close LOG;
while (1) {
print "\e[2J\n";
open LOG, ">>$0.log";
#aktuelle zeit, als fortlaufende zahl
my $atime=time;
printf "program runs since %s (for %d seconds)\n\n", $t, $atime-$starttime;
printf "%7s | %15s | %5s | %15s | %s | %s\n", "SESSION", "MCAST Grp", "Port", "Interface", "Open", "Last Data";
foreach (sort keys %mcasts) {
my ($session,$IP,$PORT,$IF)=split /:/,$_;
my $open="no";
$open="yes" if ($mcopen{$_} == 1);
if ($mcdata{$_} eq "") {
printf "%7d | %15s | %5s | %15s | %4s | %s\n", $session, $IP, $PORT, $IF, $open, 'NEVER';
}
else {
if ($atime-$mcasts{$_} > $TimeOut) {
printf "%7d | %15s | %5s | %15s | %4s | more than %d sec ago\n", $session, $IP, $PORT, $IF, $open, $TimeOut;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime;
$lastdown=localtime;
$lastdowns=$session;
if ($hour>=7 and $hour<=19) {
if ($stream{$_} == 1) {
#printf LOG "%s\n", scalar localtime;
printf LOG "%7d | %15s | %5s | %15s | %4s | at %s down for %d seconds\n", $session, $IP, $PORT, $IF, $open, scalar localtime, $TimeOut-1;
}
$stream{$_}=0;
}
}
else {
printf "%7d | %15s | %5s | %15s | %4s | %d seconds ago\n", $session, $IP, $PORT, $IF, $open, $atime-$mcasts{$_};
if ($stream{$_} == 0) {
#printf LOG "%s\n", scalar localtime;
printf LOG "%7d | %15s | %5s | %15s | %4s | live since %s\n", $session, $IP, $PORT, $IF, $open, scalar localtime;
}
$stream{$_}=1;
}
}
}
close LOG;
printf "\nLetzter Fehler: Session $lastdowns am $lastdown\n" if ($lastdowns ne "");
printf "\nKein Fehler seit Programmstart aufgetreten\n" if ($lastdowns eq "");
printf "\nv1.8 by Andre Geissler\n";
sleep 1;
}
close LOG;
# Baut Sockets für Multicast Empfang auf und sichert die zuletzt empfangenen Daten und dazu einen Zeitstempel
sub WaitForMessage {
my ($IPPORT)=@_;
my ($SESSION, $IP, $PORT, $IF) = split/:/,$IPPORT;
my $sock;
$mcopen{$IPPORT}=0;
while (!$sock) {
$sock = IO::Socket::Multicast->new(LocalPort=>$PORT,ReuseAddr=>1);
sleep 1;
}
$sock->mcast_add($IP, $IF);
$mcopen{$IPPORT}=1;
#my $data;
while (1) {
my $data;
$sock->recv($data,0);
$mcdata{$IPPORT}="DATA"; # received in the last $TimeOut seconds"; #$data;
$mcasts{$IPPORT}=time;
}
}

View File

@@ -0,0 +1,118 @@
#!/usr/bin/perl
$|=1;
use Thread;
use IO::Socket::Multicast;
#use Win32::Console::ANSI qw /Cursor Title/;
#use Term::ANSIScreen qw /:screen :cursor/;
use strict;
my %mcasts :shared;
my %mcdata :shared;
my %mcopen :shared;
my %stream :shared;
my $thr;
my $TimeOut = 10;
my $starttime;
my $lastdown;
my $lastdowns;
# Konfigdatei einlesen
open CONF, "<$0.conf";
my @config=<CONF>;
close CONF;
foreach (@config) {
chomp;
next if ($_ =~ /^#/);
next if (length($_)==0);
$_ =~ s/\r//g;
$mcasts{$_}='';
}
# Threads für die einzelnen Multicastgruppen anstarten
foreach (keys %mcasts) { $thr = new Thread (\&WaitForMessage,$_); }
# Startzeit, lesbar
my $t=localtime;
# startzeit, als fortlaufende zahl
$starttime = time;
# Anzeige aufbauen
open LOG, ">$0.log";
printf LOG "%15s | %15s | %5s | %15s | %s | %s\n", "SESSION", "MCAST Grp", "Port", "Interface", "Open", "Last Data";
close LOG;
while (1) {
print "\e[2J\n";
open LOG, ">>$0.log";
#aktuelle zeit, als fortlaufende zahl
my $atime=time;
printf "program runs since %s (for %d seconds)\n\n", $t, $atime-$starttime;
printf "%15s | %15s | %5s | %15s | %s | %s\n", "SESSION", "MCAST Grp", "Port", "Interface", "Open", "Last Data";
foreach (sort keys %mcasts) {
my ($session,$IP,$PORT,$IF)=split /:/,$_;
my $open="no";
$open="yes" if ($mcopen{$_} == 1);
if ($mcdata{$_} eq "") {
printf "%15s | %15s | %5s | %15s | %4s | %s\n", $session, $IP, $PORT, $IF, $open, 'NEVER';
}
else {
if ($atime-$mcasts{$_} > $TimeOut) {
printf "%15s | %15s | %5s | %15s | %4s | more than %d sec ago\n", $session, $IP, $PORT, $IF, $open, $TimeOut;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime;
$lastdown=localtime;
$lastdowns=$session;
if ($hour>=7 and $hour<=19) {
if ($stream{$_} == 1) {
#printf LOG "%s\n", scalar localtime;
printf LOG "%15s | %15s | %5s | %15s | %4s | at %s down for %d seconds\n", $session, $IP, $PORT, $IF, $open, scalar localtime, $TimeOut-1;
}
$stream{$_}=0;
}
}
else {
printf "%15s | %15s | %5s | %15s | %4s | %d seconds ago\n", $session, $IP, $PORT, $IF, $open, $atime-$mcasts{$_};
if ($stream{$_} == 0) {
#printf LOG "%s\n", scalar localtime;
printf LOG "%15s | %15s | %5s | %15s | %4s | live since %s\n", $session, $IP, $PORT, $IF, $open, scalar localtime;
}
$stream{$_}=1;
}
}
}
close LOG;
printf "\nLetzter Fehler: Session $lastdowns am $lastdown\n" if ($lastdowns ne "");
printf "\nKein Fehler seit Programmstart aufgetreten\n" if ($lastdowns eq "");
printf "\nv1.9 by Andre Geissler\n";
sleep 1;
}
close LOG;
# Baut Sockets für Multicast Empfang auf und sichert die zuletzt empfangenen Daten und dazu einen Zeitstempel
sub WaitForMessage {
my ($IPPORT)=@_;
my ($SESSION, $IP, $PORT, $IF) = split/:/,$IPPORT;
my $sock;
$mcopen{$IPPORT}=0;
while (!$sock) {
$sock = IO::Socket::Multicast->new(LocalPort=>$PORT,ReuseAddr=>1);
sleep 1;
}
$sock->mcast_add($IP, $IF);
$mcopen{$IPPORT}=1;
#my $data;
while (1) {
my $data;
$sock->recv($data,0);
$mcdata{$IPPORT}="DATA"; # received in the last $TimeOut seconds"; #$data;
$mcasts{$IPPORT}=time;
}
}

View File

@@ -0,0 +1,126 @@
#!/usr/bin/perl
$|=1;
use Thread;
use IO::Socket::Multicast;
#use Win32::Console::ANSI qw /Cursor Title/;
#use Term::ANSIScreen qw /:screen :cursor/;
use strict;
my %mcasts :shared;
my %mcdata :shared;
my %mcopen :shared;
my %stream :shared;
my $thr;
my $TimeOut = 10;
my $starttime;
my $lastdown;
my $lastdowns;
my @config;
# Konfigdatei einlesen wenn keine Konfig per Kommandozeile angegeben wurde
if ($ARGV[0] ne "") {
open CONF, "<$ARGV[0]" or die "Konfigdatei $ARGV[0] nicht gefunden";
@config=<CONF>;
close CONF;
} else {
open CONF, "<$0.conf" or die "Konfigdatei $0.conf nicht gefunden";
@config=<CONF>;
close CONF;
}
foreach (@config) {
chomp;
next if ($_ =~ /^#/);
next if (length($_)==0);
$_ =~ s/\r//g;
$mcasts{$_}='';
}
# Threads für die einzelnen Multicastgruppen anstarten
foreach (keys %mcasts) { $thr = new Thread (\&WaitForMessage,$_); }
# Startzeit, lesbar
my $t=localtime;
# startzeit, als fortlaufende zahl
$starttime = time;
# Anzeige aufbauen
open LOG, ">$0.log";
printf LOG "%15s | %15s | %5s | %15s | %s | %s\n", "SESSION", "MCAST Grp", "Port", "Interface", "Open", "Last Data";
close LOG;
while (1) {
print "\e[2J\n";
open LOG, ">>$0.log";
#aktuelle zeit, als fortlaufende zahl
my $atime=time;
printf "program runs since %s (for %d seconds)\n\n", $t, $atime-$starttime;
printf "%15s | %15s | %5s | %15s | %s | %s\n", "SESSION", "MCAST Grp", "Port", "Interface", "Open", "Last Data";
foreach (sort keys %mcasts) {
my ($session,$IP,$PORT,$IF)=split /:/,$_;
my $open="no";
$open="yes" if ($mcopen{$_} == 1);
if ($mcdata{$_} eq "") {
printf "%15s | %15s | %5s | %15s | %4s | %s\n", $session, $IP, $PORT, $IF, $open, 'NEVER';
}
else {
if ($atime-$mcasts{$_} > $TimeOut) {
printf "%15s | %15s | %5s | %15s | %4s | more than %d sec ago\n", $session, $IP, $PORT, $IF, $open, $TimeOut;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime;
$lastdown=localtime;
$lastdowns=$session;
if ($hour>=7 and $hour<=19) {
if ($stream{$_} == 1) {
#printf LOG "%s\n", scalar localtime;
printf LOG "%15s | %15s | %5s | %15s | %4s | at %s down for %d seconds\n", $session, $IP, $PORT, $IF, $open, scalar localtime, $TimeOut-1;
}
$stream{$_}=0;
}
}
else {
printf "%15s | %15s | %5s | %15s | %4s | %d seconds ago\n", $session, $IP, $PORT, $IF, $open, $atime-$mcasts{$_};
if ($stream{$_} == 0) {
#printf LOG "%s\n", scalar localtime;
printf LOG "%15s | %15s | %5s | %15s | %4s | live since %s\n", $session, $IP, $PORT, $IF, $open, scalar localtime;
}
$stream{$_}=1;
}
}
}
close LOG;
printf "\nLetzter Fehler: Session $lastdowns am $lastdown\n" if ($lastdowns ne "");
printf "\nKein Fehler seit Programmstart aufgetreten\n" if ($lastdowns eq "");
printf "\nv2.0 by Andre Geissler\n";
printf "\nAuf neueren Linuxsystemen in /etc/sysctl.conf\n net.ipv4.conf.all.rp_filter=0\n net.ipv4.conf.NICNAME.rp_filter=2\nsetzen";
sleep 1;
}
close LOG;
# Baut Sockets für Multicast Empfang auf und sichert die zuletzt empfangenen Daten und dazu einen Zeitstempel
sub WaitForMessage {
my ($IPPORT)=@_;
my ($SESSION, $IP, $PORT, $IF) = split/:/,$IPPORT;
my $sock;
$mcopen{$IPPORT}=0;
while (!$sock) {
$sock = IO::Socket::Multicast->new(LocalPort=>$PORT,ReuseAddr=>1);
sleep 1;
}
$sock->mcast_add($IP, $IF);
$mcopen{$IPPORT}=1;
#my $data;
while (1) {
my $data;
next unless $sock->recv($data,1024);
$mcdata{$IPPORT}="DATA"; # received in the last $TimeOut seconds"; #$data;
$mcasts{$IPPORT}=time;
}
}

Binary file not shown.

View File

@@ -0,0 +1,23 @@
# comments (#) are allowed
# complete empty line are allowed (no spaces)
# ServiceID:MulticastAddress:Port:MulticastInterfaceIP
emdi P A 1:234.56.78.90:45678:192.168.88.110
emdi P A 2:234.56.78.90:45678:192.168.88.110
emdi P A 3:234.56.78.90:45678:192.168.88.110
emdi P A 4:234.56.78.90:45678:192.168.88.110
emdi P B 1:234.56.78.90:45678:192.168.88.110
emdi P B 2:234.56.78.90:45678:192.168.88.110
emdi P B 3:234.56.78.90:45678:192.168.88.110
emdi P B 4:234.56.78.90:45678:192.168.88.110
emdi S A 1:234.56.78.90:45678:192.168.88.110
emdi S A 2:234.56.78.90:45678:192.168.88.110
emdi S A 3:234.56.78.90:45678:192.168.88.110
emdi S A 4:234.56.78.90:45678:192.168.88.110
emdi S B 1:234.56.78.90:45678:192.168.88.110
emdi S B 2:234.56.78.90:45678:192.168.88.110
emdi S B 3:234.56.78.90:45678:192.168.88.110
emdi S B 4:234.56.78.90:45678:192.168.88.110

View File

@@ -0,0 +1 @@
SESSION | MCAST Grp | Port | Interface | Open | Last Data

View File

@@ -0,0 +1,127 @@
#!/usr/bin/perl
#perl2exe_include attributes;
$|=1;
use Thread;
use IO::Socket::Multicast;
use Win32::Console::ANSI qw /Cursor Title/;
use Term::ANSIScreen qw /:screen :cursor/;
use strict;
my %mcasts :shared;
my %mcdata :shared;
my %mcopen :shared;
my %stream :shared;
my $thr;
my $TimeOut = 10;
my $starttime;
my $lastdown;
my $lastdowns;
my @config;
# Konfigdatei einlesen wenn keine Konfig per Kommandozeile angegeben wurde
if ($ARGV[0] ne "") {
open CONF, "<$ARGV[0]" or die "Konfigdatei $ARGV[0] nicht gefunden";
@config=<CONF>;
close CONF;
} else {
open CONF, "<$0.conf" or die "Konfigdatei $0.conf nicht gefunden";
@config=<CONF>;
close CONF;
}
foreach (@config) {
chomp;
next if ($_ =~ /^#/);
next if (length($_)==0);
$_ =~ s/\r//g;
$mcasts{$_}='';
}
# Threads für die einzelnen Multicastgruppen anstarten
foreach (keys %mcasts) { $thr = new Thread (\&WaitForMessage,$_); }
# Startzeit, lesbar
my $t=localtime;
# startzeit, als fortlaufende zahl
$starttime = time;
# Anzeige aufbauen
open LOG, ">$0.log";
printf LOG "%15s | %15s | %5s | %15s | %s | %s\n", "SESSION", "MCAST Grp", "Port", "Interface", "Open", "Last Data";
close LOG;
while (1) {
print "\e[2J\n";
open LOG, ">>$0.log";
#aktuelle zeit, als fortlaufende zahl
my $atime=time;
printf "program runs since %s (for %d seconds)\n\n", $t, $atime-$starttime;
printf "%15s | %15s | %5s | %15s | %s | %s\n", "SESSION", "MCAST Grp", "Port", "Interface", "Open", "Last Data";
foreach (sort keys %mcasts) {
my ($session,$IP,$PORT,$IF)=split /:/,$_;
my $open="no";
$open="yes" if ($mcopen{$_} == 1);
if ($mcdata{$_} eq "") {
printf "%15s | %15s | %5s | %15s | %4s | %s\n", $session, $IP, $PORT, $IF, $open, 'NEVER';
}
else {
if ($atime-$mcasts{$_} > $TimeOut) {
printf "%15s | %15s | %5s | %15s | %4s | more than %d sec ago\n", $session, $IP, $PORT, $IF, $open, $TimeOut;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime;
$lastdown=localtime;
$lastdowns=$session;
if ($hour>=7 and $hour<=19) {
if ($stream{$_} == 1) {
#printf LOG "%s\n", scalar localtime;
printf LOG "%15s | %15s | %5s | %15s | %4s | at %s down for %d seconds\n", $session, $IP, $PORT, $IF, $open, scalar localtime, $TimeOut-1;
}
$stream{$_}=0;
}
}
else {
printf "%15s | %15s | %5s | %15s | %4s | %d seconds ago\n", $session, $IP, $PORT, $IF, $open, $atime-$mcasts{$_};
if ($stream{$_} == 0) {
#printf LOG "%s\n", scalar localtime;
printf LOG "%15s | %15s | %5s | %15s | %4s | live since %s\n", $session, $IP, $PORT, $IF, $open, scalar localtime;
}
$stream{$_}=1;
}
}
}
close LOG;
printf "\nLetzter Fehler: Session $lastdowns am $lastdown\n" if ($lastdowns ne "");
printf "\nKein Fehler seit Programmstart aufgetreten\n" if ($lastdowns eq "");
printf "\nv2.0 by Andre Geissler\n";
printf "\nAuf neueren Linuxsystemen in /etc/sysctl.conf\n net.ipv4.conf.all.rp_filter=0\n net.ipv4.conf.NICNAME.rp_filter=2\nsetzen";
sleep 1;
}
close LOG;
# Baut Sockets für Multicast Empfang auf und sichert die zuletzt empfangenen Daten und dazu einen Zeitstempel
sub WaitForMessage {
my ($IPPORT)=@_;
my ($SESSION, $IP, $PORT, $IF) = split/:/,$IPPORT;
my $sock;
$mcopen{$IPPORT}=0;
while (!$sock) {
$sock = IO::Socket::Multicast->new(LocalPort=>$PORT,ReuseAddr=>1);
sleep 1;
}
$sock->mcast_add($IP, $IF);
$mcopen{$IPPORT}=1;
#my $data;
while (1) {
my $data;
next unless $sock->recv($data,64);
$mcdata{$IPPORT}="DATA"; # received in the last $TimeOut seconds"; #$data;
$mcasts{$IPPORT}=time;
}
}

View File

@@ -0,0 +1,23 @@
# comments (#) are allowed
# complete empty line are allowed (no spaces)
# ServiceID:MulticastAddress:Port:MulticastInterfaceIP
emdi P A 1:234.56.78.90:45678:192.168.88.110
emdi P A 2:234.56.78.90:45678:192.168.88.110
emdi P A 3:234.56.78.90:45678:192.168.88.110
emdi P A 4:234.56.78.90:45678:192.168.88.110
emdi P B 1:234.56.78.90:45678:192.168.88.110
emdi P B 2:234.56.78.90:45678:192.168.88.110
emdi P B 3:234.56.78.90:45678:192.168.88.110
emdi P B 4:234.56.78.90:45678:192.168.88.110
emdi S A 1:234.56.78.90:45678:192.168.88.110
emdi S A 2:234.56.78.90:45678:192.168.88.110
emdi S A 3:234.56.78.90:45678:192.168.88.110
emdi S A 4:234.56.78.90:45678:192.168.88.110
emdi S B 1:234.56.78.90:45678:192.168.88.110
emdi S B 2:234.56.78.90:45678:192.168.88.110
emdi S B 3:234.56.78.90:45678:192.168.88.110
emdi S B 4:234.56.78.90:45678:192.168.88.110

View File

@@ -0,0 +1 @@
SESSION | MCAST Grp | Port | Interface | Open | Last Data