-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsServerUp
More file actions
169 lines (155 loc) · 5.45 KB
/
Copy pathIsServerUp
File metadata and controls
169 lines (155 loc) · 5.45 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#! /usr/bin/perl
use 5.16.1;
use strict;
use warnings;
use Net::Ping;
#Name: Eli Harris
#Email: ehharris@rams.colostate.edu
#Date: 10/21
#Class: CT320
#Assign: HW4/up
my ($option, $option2, $option3, $number, $why) = @ARGV;
my $p = Net::Ping->new();
my $v = 1;
my $count = 3;
if(not defined $option){
die "Error in program $0: No input args, usage = (options) 'address to ping' \n";
}
if(not defined $option2){
my $success = 0;
foreach my $c (1 .. $count) {
my ($ret, $duration, $ip) = $p->ping($option);
if ($ret) {
$success++;
}
}
print "$option: $success/$count\n"
}elsif(not defined $option3){
if ($option eq "-s"){
my $success = 0;
foreach my $c (1 .. $count) {
my ($ret, $duration, $ip) = $p->ping($option2);
if ($ret) {
$success++;
}
}
if($success lt $count){
print "$option2: $success/$count\n"
}
}
if ($option eq "-p"){
die "Error in program $0: Need count for ping if using -p, usage = (options) 'address to ping' \n";
}
my ($pe, $numba) = (split /p/, $option)[0, 1];
if ($pe ne "-") { die "Error in program $0: $pe not an option, usage = (options) 'address to ping' \n";}
if ( $numba =~ /^[0-9]+$/ ) {
my $success = 0;
foreach my $c (1 .. $numba) {
my ($ret, $duration, $ip) = $p->ping($option2);
if ($ret) {
$success++;
}
}
print "$option2: $success/$numba\n"
} else {
die "Error in program $0: $numba isn't a number, usage = (options) 'address to ping' \n";
}
}elsif(not defined $number){
if ($option eq "-s"){
if ($option2 eq "-p"){
die "Error in program $0: Need count for ping if using -p, usage = (options) 'address to ping' \n";
}
my ($pe, $numba) = (split /p/, $option2)[0, 1];
if ($pe ne "-") { die "Error in program $0: $pe not an option, usage = (options) 'address to ping' \n";}
if ( $numba =~ /^[0-9]+$/ ) {
my $success = 0;
foreach my $c (1 .. $numba) {
my ($ret, $duration, $ip) = $p->ping($option3);
if ($ret) {
$success++;
}
}
if($success lt $numba){
print "$option3: $success/$numba\n"
}
} else {
die "Error in program $0: $numba isn't a number, usage = (options) 'address to ping' \n";
}
} elsif ($option eq "-p"){
if ( $option2 =~ /^[0-9]+$/ ) {
my $success = 0;
foreach my $d (1 .. $option2) {
my ($ret, $duration, $ip) = $p->ping($option3);
if ($ret) {
$success++;
}
}
print "$option3: $success/$option2\n"
} else {
die "Error in program $0: $option2 isn't a number or '-s', usage = (options) 'address to ping' \n";
}
} else {
my ($pe, $numba) = (split /p/, $option)[0, 1];
if ($pe ne "-") { die "Error in program $0: $pe not an option, usage = (options) 'address to ping' \n";}
if($option2 eq "-s"){
if ( $numba =~ /^[0-9]+$/ ) {
my $success = 0;
foreach my $c (1 .. $numba) {
my ($ret, $duration, $ip) = $p->ping($option3);
if ($ret) {
$success++;
}
}
if($success lt $numba){
print "$option3: $success/$numba\n"
}
} else {
die "Error in program $0: $numba isn't a number, usage = (options) 'address to ping' \n";
}
}
}
}elsif (defined $why){
die "Error in program $0: Wrong number of args, usage = (options) 'address to ping' \n";
} else {
if ($option eq "-p"){
if ($option3 eq "-s"){
if ( $option2 =~ /^[0-9]+$/ ) {
my $success = 0;
foreach my $c (1 .. $option2) {
my ($ret, $duration, $ip) = $p->ping($number);
if ($ret) {
$success++;
}
}
if($success lt $option2){
print "$number: $success/$option2\n"
}
} else {
die "Error in program $0: $option2 isn't a number, usage = (options) 'address to ping' \n";
}
} else {
die "Error in program $0: Wrong use of args, usage = (options) 'address to ping' \n";
}
} elsif ($option eq "-s"){
if ($option2 eq "-p"){
if ( $option3 =~ /^[0-9]+$/ ) {
my $success = 0;
foreach my $c (1 .. $option3) {
my ($ret, $duration, $ip) = $p->ping($number);
if ($ret) {
$success++;
}
}
if($success lt $option3){
print "$number: $success/$option3\n"
}
} else {
die "Error in program $0: $option3 isn't a number, usage = (options) 'address to ping' \n";
}
} else {
die "Error in program $0: Wrong use of args, usage = (options) 'address to ping' \n";
}
} else {
die "Error in program $0: Wrong use of args, usage = (options) 'address to ping' \n";
}
}