Class: TplinkCli::App
- Inherits:
-
Thor
- Object
- Thor
- TplinkCli::App
- Defined in:
- lib/tplink-cli/app.rb
Instance Method Summary collapse
Instance Method Details
#config ⇒ Object
12 13 14 15 |
# File 'lib/tplink-cli/app.rb', line 12 def config Configuration.save exec "$EDITOR #{ENV['HOME']}/.tplinkcli" end |
#hosts ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tplink-cli/app.rb', line 39 def hosts payload = "[LAN_HOST_ENTRY#0,0,0,0,0,0#0,0,0,0,0,0]0,4\r\nleaseTimeRemaining\r\nMACAddress\r\nhostName\r\nIPAddress\r\n" response = Client.post '/cgi?5', binary: payload Iniparse.new(response).parse.to_a.tap(&:pop).each do |_,data| Configuration.instance.hosts[data['MACAddress']] ||= {} Configuration.instance.hosts[data['MACAddress']][:host_name] = data['hostName'] end Configuration.instance.hosts.each do |mac, host| puts(sprintf "%-16s %30s %30s", host[:ip_address], host[:host_name], host[:name]) end Configuration.save end |
#status ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/tplink-cli/app.rb', line 19 def status payload = "[WAN_DSL_INTF_CFG#1,0,0,0,0,0#0,0,0,0,0,0]0,12\r\nstatus\r\nmodulationType\r\nX_TPLINK_AdslModulationCfg\r\nupstreamCurrRate\r\ndownstreamCurrRate\r\nX_TPLINK_AnnexType\r\nupstreamMaxRate\r\ndownstreamMaxRate\r\nupstreamNoiseMargin\r\ndownstreamNoiseMargin\r\nupstreamAttenuation\r\ndownstreamAttenuation\r\n[WAN_DSL_INTF_STATS_TOTAL#1,0,0,0,0,0#0,0,0,0,0,0]1,8\r\nATUCCRCErrors\r\nCRCErrors\r\nATUCFECErrors\r\nFECErrors\r\nSeverelyErroredSecs\r\nX_TPLINK_US_SeverelyErroredSecs\r\nerroredSecs\r\nX_TPLINK_US_ErroredSecs\r\n" response = Client.post '/cgi?1&5', binary: payload Iniparse.parse(response)["[1,0,0,0,0,0]0"].each do |key,value| puts(sprintf "%-40s %-20s", key, value) end Configuration.save end |
#traffic ⇒ Object
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 |
# File 'lib/tplink-cli/app.rb', line 54 def traffic payload = "[STAT_CFG#0,0,0,0,0,0#0,0,0,0,0,0]0,0\r\n[STAT_ENTRY#0,0,0,0,0,0#0,0,0,0,0,0]1,0\r\n" response = Client.post '/cgi?1&5', binary: payload structure = Iniparse.parse(response).to_a # remove first & last structure.shift; structure.pop Configuration.instance.hosts ||= {} Configuration.instance.hosts.each do |mac, host| host[:current_bytes] = 0 end structure.each do |_, data| Configuration.instance.hosts[ data['macAddress'] ] ||= {} Configuration.instance.hosts[ data['macAddress'] ][:ip_address] = num2ip(data['ipAddress']) Configuration.instance.hosts[ data['macAddress'] ][:total_bytes] = data['totalBytes'] Configuration.instance.hosts[ data['macAddress'] ][:current_bytes] = data['currBytes'] end length = Configuration.instance.hostname_length ||= 16 Configuration.instance.hosts.each do |mac, host| string = (host[:name] || host[:host_name] || "").chars.take(length).join puts(sprintf "%-16s %#{length}s %8.1f kb/10s %6.1f kb/s", host[:ip_address], string, host[:current_bytes] / 1024, host[:current_bytes] / 10024) end Configuration.save end |