Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- # udpqotd - UDP message server
- use strict;
- use IO::Socket;
- my(@pids, $i, $sock, $replymsg, $newmsg, $hisaddr, $hishost, $MAXLEN, $PORTNO);
- $MAXLEN = 1024;
- $PORTNO = 9595;
- $sock = IO::Socket::INET->new(
- LocalPort => $PORTNO,
- Proto => 'udp',
- ) or die "socket: $@";
- print "Awaiting UDP messages on port $PORTNO\n";
- while ($sock->recv($newmsg, $MAXLEN)) {
- if($newmsg =~ /failure$/){
- my($port, $ipaddr) = sockaddr_in($sock->peername);
- $hishost = gethostbyaddr($ipaddr, AF_INET);
- print "Client on $hishost discovered irc Service $newmsg\n";
- $replymsg = "Services Starting";
- $sock->send($replymsg);
- system('~/services/services.pl');
- }
- elsif($newmsg =~ /started$/){
- my($port, $ipaddr) = sockaddr_in($sock->peername);
- $hishost = gethostbyaddr($ipaddr, AF_INET);
- print "IRC Services started on $hishost, killing local services.pl\n";
- open(PIDOF_PIPE,"pidof -x services.pl|");
- while (<PIDOF_PIPE>){
- chomp;
- my $count = scalar(@pids);
- @pids = split(' ', $_);
- $i = 0;
- foreach $count (@pids){
- system("kill","$pids[$i]");
- print "[KILLED] $pids[$i]\n";
- $i++;
- }
- }
- }
- else{
- $replymsg = "Unrecognized Command Recived";
- $sock->send($replymsg);
- }
- }
- die "recv: $!";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement