File Coverage

blib/lib/Net/Telnet/Netgear/Packet.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 4 4 100.0
total 23 23 100.0


line stmt bran cond sub pod time code
1             package Net::Telnet::Netgear::Packet;
2 5     5   24 use strict;
  5         7  
  5         183  
3 5     5   25 use warnings;
  5         6  
  5         1053  
4            
5             sub new
6             {
7 11     11 1 5233 require Net::Telnet::Netgear::Packet::Native;
8 11         66 Net::Telnet::Netgear::Packet::Native->new (splice (@_, 1));
9             }
10            
11             sub from_string
12             {
13 3     3 1 5345 require Net::Telnet::Netgear::Packet::String;
14 3         22 Net::Telnet::Netgear::Packet::String->new (splice (@_, 1));
15             }
16            
17             sub from_base64
18             {
19 3     3 1 25 require Net::Telnet::Netgear::Packet::String;
20 3         14 Net::Telnet::Netgear::Packet::String->from_base64 (splice (@_, 1));
21             }
22            
23             sub get_packet
24             {
25 1     1 1 499 die "Method 'get_packet' not implemented in subclass";
26             }
27            
28             1;
29            
30             =encoding utf8
31            
32             =head1 NAME
33            
34             Net::Telnet::Netgear::Packet - generates "telnet enable packets" for Netgear routers
35            
36             =head1 SYNOPSIS
37            
38             use Net::Telnet::Netgear::Packet;
39             # From a string
40             my $packet = Net::Telnet::Netgear::Packet->from_string ('...');
41             # From a Base64-encoded string
42             my $packet = Net::Telnet::Netgear::Packet->from_base64 ('Li4u');
43             # From the MAC address of the router
44             my $packet = Net::Telnet::Netgear::Packet->new (
45             mac => 'AA:BB:CC:DD:EE:FF',
46             username => 'admin', # optional
47             password => 'hunter2' # optional
48             );
49             # Gets the packet as a string.
50             my $string = $packet->get_packet;
51            
52             =head1 DESCRIPTION
53            
54             This module allows to generate "telnet enable packets" usable with Netgear routers to unlock the
55             telnet interface.
56            
57             You can either provide a pre-generated packet from a string or you can let the module generate
58             it with the MAC address of the router. It's also possible to specify the username and password
59             that will be put in the packet.
60            
61             This module is just a wrapper - the code which handles the packets
62             is in C or C,
63             depending on which constructor you use.
64            
65             =head1 METHODS
66            
67             =head2 new
68            
69             my $packet = Net::Telnet::Netgear::Packet->new (%options);
70            
71             Creates a C instance.
72            
73             C<%options> can be populated with the following items:
74            
75             =over 4
76            
77             =item * C<< mac => 'AA:BB:CC:DD:EE' >>
78            
79             The MAC address of your router. I
80            
81             =item * C<< username => 'admin' >>
82            
83             Optional, the username which will be put in the packet.
84             Defaults to C for compatibility reasons.
85            
86             =item * C<< password => 'hunter2' >>
87            
88             Optional, the password which will be put in the packet.
89             Defaults to C for compatibility reasons.
90            
91             =back
92            
93             B the packet is generated each time L is called, so it's recommended
94             to store the returned value in a variable and use that instead of calling the method each time.
95            
96             =head2 from_string
97            
98             my $packet = Net::Telnet::Netgear::Packet->from_string ('str');
99            
100             Creates a C instance.
101            
102             The string has to be 128 bytes, but this check is not enforced.
103            
104             =head2 from_base64
105            
106             my $packet = Net::Telnet::Netgear::Packet->from_base64 ('...');
107            
108             Creates a C instance.
109            
110             The decoded string has to be 128 bytes, but this check is not enforced.
111            
112             =head2 get_packet
113            
114             my $packet_str = $packet->get_packet;
115            
116             Retrieves the generated packet (or the user provided one).
117            
118             This method must be implemented by the subclasses, and dies if it isn't (or if it is called
119             directly on this class).
120            
121             =head1 SEE ALSO
122            
123             L, L,
124             L.
125            
126             =head1 AUTHOR
127            
128             Roberto Frenna (robertof AT cpan DOT org)
129            
130             =head1 THANKS
131            
132             See L.
133            
134             =head1 LICENSE
135            
136             Copyright (C) 2014-2015, Roberto Frenna.
137            
138             This program is free software, you can redistribute it and/or modify it under the terms of the
139             Artistic License version 2.0.
140            
141             =cut