tp_link_commander 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/tp_link_commander.rb +63 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 95819b3e80cabc55abdc5310b44f1b5d20b6f90e
4
+ data.tar.gz: 77f164b8167dd7e99feca21a0382256b82869911
5
+ SHA512:
6
+ metadata.gz: 575c36048d1bb3d7afb4270f0d5bdab6c5d446079f75ab8a9f208b15a33f3b366671abd87fc9707d1c3b077cd49ca32baf2b587afd28f5c904c183eebcd22862
7
+ data.tar.gz: 53ae962db6047a6882fafcfbb289da816a1d0a181ff68565ff64121aa64b30c45ad0468cceba4df21c9e308071ad8c32d2fdcd905791f820508e7c017004d1d2
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'base64'
5
+ class TPLinkCommander
6
+ def initialize(local_ip,login,pass)
7
+ @local_ip=local_ip
8
+ @login=login
9
+ @pass=pass
10
+ end
11
+ def get_auth
12
+ "Basic #{Base64.encode64("#{@login}:#{@pass}").gsub(/[^A-Za-z0-9=]/,"")}"
13
+ end
14
+ def get(url)
15
+ url = URI("http://#{@local_ip}/#{url}")
16
+ http = Net::HTTP.new(url.host, url.port)
17
+ request = Net::HTTP::Get.new(url)
18
+ request["Authorization"] = get_auth
19
+ response = http.request(request)
20
+ end
21
+ def next_hex(hex)
22
+ ("0x#{hex.gsub(/\-/,"")}".to_i(16)+1).to_s(16).upcase.scan(/../).join("-")
23
+ end
24
+ def get_status
25
+ response=get("userRpm/StatusRpm.htm")
26
+ result=response.read_body
27
+ if result =~ /#errorbody/
28
+ nil
29
+ else
30
+ params=result.gsub(/^[\S\s]+wanPara\s=\snew\sArray\(|\);[\S\s]+$/,"").split(/"?\s*,\s*"?/)
31
+ @mac=params[1]
32
+ @next_mac=next_hex(@mac)
33
+ @wan_ip=params[2]
34
+ params
35
+ end
36
+ end
37
+ def change_mac(new_mac)
38
+ get("userRpm/MacCloneCfgRpm.htm?mac1=#{new_mac}&wan=1&Save=%25E5%2584%25B2%25E5%25AD%2598")
39
+ end
40
+
41
+ def change_ip
42
+ if !get_status.nil?
43
+ ip=@wan_ip
44
+ new_ip='0.0.0.0'
45
+ loop do
46
+ change_mac(@next_mac)
47
+ sleep 15
48
+ loop do
49
+ get_status
50
+ new_ip=@wan_ip
51
+ sleep 5
52
+ if new_ip!='0.0.0.0'
53
+ print "[#{ip} -> #{new_ip}] "
54
+ end
55
+ break if new_ip!='0.0.0.0'
56
+ end
57
+ break if new_ip!=ip
58
+ end
59
+ else
60
+ puts "Authorization Failed!"
61
+ end
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tp_link_commander
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Cloudgen Wong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Currently for TP LINK Version 3.16.5 Only
14
+ email: cloudgen.wong@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/tp_link_commander.rb
20
+ homepage: http://w0ng.hk/tp_link_commander.html
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.5.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Control the TP LINK Wifi Router
44
+ test_files: []