1 2 3 4 5 6 7 8 9 10
use POSIX qw/setsid/; my $pid = fork(); die $! unless defined $pid; if($pid == 0) { die $! unless setsid(); } else { exit(); }
1
2
POSIX::setsid not implemented on this architecture at C:\Users\Tester\Desktop\te
st.pl line 6.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
package IPnum; use strict; use warnings; use Net::Ping; use Carp; use overload '++' => \&increase; # IP, NUM hochzählen sub increase{ my $self = shift; my $num = unpack "N", pack("CCCC", split /\./, $self->{IP}); $num++; # Oktetten neu berechnen my $ip = join(".", unpack("CCCC", pack("N", $num))); $self->{IP} = $ip; $self->{NUM} = $num; } # Einfaches IP-Objekt erstellen sub new{ my $class = shift; my $ip = shift; my @octs = split /\./, $ip; # each octet must be a number!!! foreach my $o(@octs){ if($o !~ /^\d+$/){ croak "Unwise Octet" } } # IP numerisch my $num = unpack "N", pack("CCCC", @octs); # zum Prüfen einmal hin und zurück rechnen my $hip = join(".", unpack("CCCC", pack("N", $num))); croak "invalid IP-Address" if $ip ne $hip; my $self = { NUM => $num, PING => Net::Ping->new('icmp'), IP => $ip, }; return bless $self, $class; } # Delegation Net::Ping::ping sub ping{ my $self = shift; return $self->{PING}->ping($self->{NUM}, 0.3); } # zum Testen sub dump{ my $self = shift; printf "IP: %s\nNUM: %s\n", $self->{IP}, $self->{NUM}; } # IP Adresse rausgeben sub getip{ return shift->{IP}; } 1;######################################################################### package main; use File::Temp qw(tempfile); $|=1; binmode STDOUT; my ($fh, $fname) = tempfile; binmode $fh; # Anzahl der Prozesse my $nop = 14; # Startadresse my $ipo = IPnum->new('10.0.0.1'); # Ab geht die Post ;) foreach my $n(1..$nop){ my $pid = fork(); if($pid){ if($pid == waitpid($pid, 0)){ print "#"; } } elsif($pid == 0){ my $ip = $ipo->getip; my $status = $ipo->ping; print $fh pack("Z100", qq(ping $ip, Status: $status)); exit 0; } else{ die "Forken geht hier nicht"; } # Incease IP-Address $ipo++; } print "\n\n Done!!! \n\n"; seek $fh, 0, 0; while(read $fh, my $buffer, 100){ print unpack("Z100", $buffer), "\n"; } close $fh;