-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_pair.pl
More file actions
executable file
·142 lines (105 loc) · 3.22 KB
/
Copy pathtest_pair.pl
File metadata and controls
executable file
·142 lines (105 loc) · 3.22 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
#! /usr/bin/perl
#----------------------------------------------------------------------#
# Source code by Alvin Alexander, devdaily.com
#----------------------------------------------------------------------#
sub promptUser {
local($promptString,$defaultValue) = @_;
if ($defaultValue) {
print $promptString, "[", $defaultValue, "]: ";
} else {
print $promptString, ": ";
}
$| = 1; # force a flush after our print
$_ = <STDIN>; # get the input from STDIN (presumably the keyboard)
chomp;
if ("$defaultValue") {
return $_ ? $_ : $defaultValue; # return $_ if it has a value
} else {
return $_;
}
}
#################################################################
## Timestamp Script ##
#################################################################
($sec,$min,$hour,$mday,$mon,$year,$wday,
$yday,$isdst)=localtime(time);
#################################################################
## Source Code by Andreas Echavez - Turnstone Telnet Script ##
#################################################################
use Net::Telnet;
if (defined $ARGV[0] and defined $ARGV[1]) {
}else{
print "\nWelcome to the Turnstone Test Pair Script.\n";
print "Usage: test_pair.pl turnstone cablepair openshort\n\n";
exit 0;
}
$oldpassword = "password_goes_here"; # Login Password
$turnstone = $ARGV[0];
$cable_pair_human = $ARGV[1];
use Number::Range;
$i = "$cable_pair_human";
for ($count = 0; $count <= 23; $count++) {
$CLXCOUNT = sprintf("%.2d", $count + 5);
$upperrange = (($count + "1") * "25");
$lowerrange = $upperrange - "24";
my $valuator = Number::Range->new("$lowerrange..$upperrange");
if ($valuator->inrange("$i")) {
$CXID = $i - ($count * 25);
$cable_pair = "CXL$CLXCOUNT\[$CXID\]";
}
}
$cable_command = "tp -f $cable_pair";
$cable_command2 = "tp -f $cable_pair openshort";
print "Logging into $turnstone ";
if ( $ARGV[2] eq "openshort" ){
print "\n -Open/Short Test Requested";
}
print "\n";
$telnet = Net::Telnet->new(Timeout => 200, errmode =>sub {&login_fail});
Prompt => ('/\$ $/i');
$telnet->open ($turnstone);
print " -Logging In\n";
$telnet->waitfor('/login: $/i');
$telnet->print('root');
$telnet->waitfor('/password: $/i');
$telnet->print($oldpassword);
print " -Getting Prompt\n";
$telnet->waitfor('/> /');
print " -Got Prompt!\n";
if ( $ARGV[2] eq "openshort"){
print " -Running $cable_command2\n";
$telnet->print($cable_command2);
$telnet->waitfor('/Should/');
print " -Confirmed Turnstone Test\n";
$telnet->print('Yes');
$telnet->print('');
$telnet->waitfor('/Press/');
{
local( $| ) = ( 1 );
print "";
print "Press <Enter> when open: ";
my $resp = <STDIN>;
}
$telnet->print('');
$telnet->waitfor('/Press/');
{
local( $| ) = ( 1 );
print "Press <Enter> when shorted: ";
my $resp = <STDIN>;
}
$telnet->print('');
}
else{
print " -Running $cable_command\n";
$telnet->print($cable_command);
$telnet->waitfor('/Should/');
print " -Confirmed Turnstone Test\n";
$telnet->print('Yes');
}
($stats) = $telnet->waitfor('/cageTS/');
print " -Getting Stats\n";
print $stats;
$telnet->close;
print "\n";
print "Complete\n\n";
exit 0;