CModem 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +26 -0
- data/lib/cmodem.rb +208 -0
- data/test/test.rb +40 -0
- metadata +48 -0
data/README
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
CModem es un conjunto de clases para facilitar la administración de los cable modems.
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
= Actualmente =
|
6
|
+
* soporta instrucciones para el Cable Modem Thomson587.
|
7
|
+
|
8
|
+
= USO =
|
9
|
+
Ejemplo
|
10
|
+
require 'rubygems'
|
11
|
+
require 'cmodem'
|
12
|
+
|
13
|
+
m = CableModemThomson587.new('192.168.1.254')
|
14
|
+
if m.autenticar('admin', 'admin')
|
15
|
+
puts "Clave y usuario si funcionan"
|
16
|
+
#llamas comando del thomson
|
17
|
+
m.c.systemlog.show.call
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
m.cerrar
|
22
|
+
Se nos crea un archivo con IP.log donde queda almacena la salida de la conexión.
|
23
|
+
|
24
|
+
C
|
25
|
+
D
|
26
|
+
m.c.systemlog.
|
data/lib/cmodem.rb
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
=begin
|
2
|
+
Libreria para administrar CableModem
|
3
|
+
(C) 2011 Jovany Leandro G.C <lenadro@manadalibre.org>
|
4
|
+
|
5
|
+
cmodem is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
any later version.
|
9
|
+
|
10
|
+
Ronela is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU General Public License
|
16
|
+
along with cmodem. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
=end
|
18
|
+
|
19
|
+
require 'net/telnet'
|
20
|
+
|
21
|
+
|
22
|
+
module CModem
|
23
|
+
|
24
|
+
#== Comando
|
25
|
+
#Esta clase hace mapeo de methodos para
|
26
|
+
#construir la linea de comandos para el cable modem
|
27
|
+
#Ejemplo
|
28
|
+
#c = Comando.new
|
29
|
+
#print c.firewall.config({:state=>:disabled}) => :firewall config state=disabled
|
30
|
+
class Comando
|
31
|
+
def initialize(n=nil, name_caller=nil, &caller)
|
32
|
+
@cmd = n.nil? ? ':' : n
|
33
|
+
@name_caller = name_caller
|
34
|
+
@caller = caller
|
35
|
+
end
|
36
|
+
|
37
|
+
def method_missing(s, *args)
|
38
|
+
|
39
|
+
if s == @name_caller
|
40
|
+
@caller.call(@cmd)
|
41
|
+
end
|
42
|
+
|
43
|
+
if @cmd == ":"
|
44
|
+
linea = @cmd + s.to_s
|
45
|
+
else
|
46
|
+
linea = @cmd + " " + s.to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
if args.size == 1
|
50
|
+
args[0].each_pair { |k,v| linea += " " + k.to_s + "=" + v.to_s }
|
51
|
+
end
|
52
|
+
|
53
|
+
Comando.new(linea, @name_caller) { |c| @caller.call(c) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_s
|
57
|
+
@cmd
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
#Agregar manejador de comandos
|
64
|
+
#cuando no exista arrojar execpcion
|
65
|
+
class CableModem < Net::Telnet
|
66
|
+
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
#Esto es configurado con el TG587
|
71
|
+
class CableModemThomson587 < CableModem
|
72
|
+
attr_reader :c
|
73
|
+
|
74
|
+
def initialize(host, timeout=10)
|
75
|
+
|
76
|
+
@options = {}
|
77
|
+
@options['Prompt'] = /.+=>\z/n
|
78
|
+
@options['Host'] = host
|
79
|
+
@options['Timeout'] = timeout
|
80
|
+
@options['Output_log'] = host+'.log'
|
81
|
+
super(@options)
|
82
|
+
@c = Comando.new(':', :call) { |c| cmd c }
|
83
|
+
@username = nil
|
84
|
+
@password = nil
|
85
|
+
end
|
86
|
+
|
87
|
+
#intenta obtener serial y mac por puerto 80
|
88
|
+
def info
|
89
|
+
require 'net/http'
|
90
|
+
res = Net::HTTP.get_response(URI("http://#{@options['Host']}/"))
|
91
|
+
|
92
|
+
#los thompson por general envia parte de la serial
|
93
|
+
#por http WWW-Authenticate
|
94
|
+
#si los dos primeros digitos CP
|
95
|
+
data = res["www-authenticate"].scan(/nonce+=\"([^,]+)\"/)[0][0].split(':')
|
96
|
+
return {:serial => data[0], :MAC => data[1]}
|
97
|
+
end
|
98
|
+
|
99
|
+
def autenticar(username, password)
|
100
|
+
#se dice que cuando logea queda el prompt con =>"
|
101
|
+
login({"LoginPrompt" => /[Uu]sername[: ]*\z/n, "Name" => username, "Password" => password}).include? "=>"
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
def cerrar
|
106
|
+
close
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
#Wife utis
|
112
|
+
def wifi_cambiar(ssid, any=true)
|
113
|
+
any = "enabled" if any
|
114
|
+
anf = "disabled" if !any
|
115
|
+
|
116
|
+
@c.wireless.ifconfig(:ssid => ssid, :any => any, :state=>:enabled).call
|
117
|
+
end
|
118
|
+
|
119
|
+
#Cambia seguridad del wifi
|
120
|
+
#@type wep o wpa o false (desactiva)
|
121
|
+
#@pass clave
|
122
|
+
def wifi_secmode(type, pass=nil)
|
123
|
+
@c.wireless.secmode.config(:mode => :disable).call
|
124
|
+
case type
|
125
|
+
when :wep
|
126
|
+
@c.wireless.secmode.wep(:encryptionkey => pass).call if !pass.nil?
|
127
|
+
@c.wireless.secmode.config(:mode => :wep).call
|
128
|
+
when :wpa
|
129
|
+
@c.wireless.secmode.send("wpa-psk", :presharedkey => pass).call if !pass.nil?
|
130
|
+
@c.wireless.secmode.config(:mode => "wpa-psk").call
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
def wifi_wps(state)
|
136
|
+
state = :enabled if state
|
137
|
+
state = :disabled if state
|
138
|
+
@c.wireless.wps.config(:state => state)
|
139
|
+
end
|
140
|
+
|
141
|
+
def wifi_wds(state)
|
142
|
+
state = :enabled if state
|
143
|
+
state = :disabled if state
|
144
|
+
@c.wireless.wds.config(:state => state)
|
145
|
+
end
|
146
|
+
|
147
|
+
#PPP utils
|
148
|
+
def ppp_cambiar(intf, user, pass)
|
149
|
+
@c.ppp.ifconfig(:intf => intf, :user => user, :password => pass).call
|
150
|
+
end
|
151
|
+
|
152
|
+
def ppp_llamar(intf)
|
153
|
+
@c.ppp.ifattach(:intf => intf).call
|
154
|
+
end
|
155
|
+
|
156
|
+
def ppp_colgar(intf)
|
157
|
+
@c.ppp.ifdetach(:intf => intf).call
|
158
|
+
end
|
159
|
+
|
160
|
+
#Limpiar Registros
|
161
|
+
def barrer
|
162
|
+
@c.ids.clear.call
|
163
|
+
|
164
|
+
#limpiar QOS
|
165
|
+
@c.ipqos.meter.clear.call
|
166
|
+
@c.ipqos.queue.clear.call
|
167
|
+
|
168
|
+
#limpiar ARP
|
169
|
+
|
170
|
+
#limpiar MEMORIA
|
171
|
+
@c.memm.debug.clearstats.call
|
172
|
+
@c.hostmgr.clear.call
|
173
|
+
end
|
174
|
+
|
175
|
+
#IP
|
176
|
+
|
177
|
+
def manifestarse_udp(addr, port=80)
|
178
|
+
@c.ip.debug.sendto(:addr => addr, :count=>1000000, :size=>20000, :interval=>1, :dstport => port).call
|
179
|
+
end
|
180
|
+
|
181
|
+
def usuario_agregar(nombre, pass, rol)
|
182
|
+
@c.user.add(:name => nombre, :password => pass, :role => rol).call
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
#Como no ser para reabrir conexiones con net/telnet
|
187
|
+
#dispongo este procedimiento
|
188
|
+
def self.script(ip, &block)
|
189
|
+
c = self.new(ip)
|
190
|
+
c.instance_eval(&block)
|
191
|
+
c.close
|
192
|
+
end
|
193
|
+
|
194
|
+
#Prueba nombre y clave para autenticarse
|
195
|
+
def self.autenticable?(ip, nombre, pass)
|
196
|
+
c = self.new(ip)
|
197
|
+
q = c.autenticar(nombre, pass)
|
198
|
+
c.close
|
199
|
+
q
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
data/test/test.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "#{Dir.pwd}/cmodem"
|
3
|
+
|
4
|
+
IP = '192.168.1.254'
|
5
|
+
|
6
|
+
|
7
|
+
#Ejemplo Probar claves
|
8
|
+
def probar_claves(ip, claves)
|
9
|
+
|
10
|
+
claves.each { |c|
|
11
|
+
m = CModem::CableModemThomson587.new(ip)
|
12
|
+
r = m.autenticar(c[:nombre], c[:clave])
|
13
|
+
puts "IP: #{ip} nombre:#{c[:nombre]} clave:#{c[:clave]} Autentica? #{r}"
|
14
|
+
m.cerrar
|
15
|
+
}
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
probar_claves(IP, [
|
20
|
+
{:nombre => 'admin', :clave => 'admin'},
|
21
|
+
{:nombre => 'tech', :clave => 'tech'},
|
22
|
+
{:nombre => 'admin', :clave => ''}
|
23
|
+
])
|
24
|
+
|
25
|
+
|
26
|
+
#Ejemplo adivinar clave
|
27
|
+
m = CModem::CableModemThomson587.new(IP)
|
28
|
+
if m.autenticar('admin', "CPE##{m.info[:serial][-6..-1]}")
|
29
|
+
puts "IP: #{IP} Autenticación automática con CPE# funciona"
|
30
|
+
else
|
31
|
+
puts "IP: #{IP} No autentica automáticamente co CPE#"
|
32
|
+
end
|
33
|
+
|
34
|
+
#cliente.ppp_cambiar('Internet', 'aoeu', 1234)
|
35
|
+
#cliente.usuario_agregar('roota', 'roota', 'root')
|
36
|
+
#loop {
|
37
|
+
# cliente.manifestarse_udp('192.168.1.64')
|
38
|
+
#}
|
39
|
+
|
40
|
+
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: CModem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jovany Leandro G.C
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-23 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email: info@manadalibre.org
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files:
|
19
|
+
- README
|
20
|
+
files:
|
21
|
+
- lib/cmodem.rb
|
22
|
+
- test/test.rb
|
23
|
+
- README
|
24
|
+
homepage:
|
25
|
+
licenses: []
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.11
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: Administrador Cable Modem
|
48
|
+
test_files: []
|