From 18cc06b9c1cd95bbadfa3f52aad21fd87acc9885 Mon Sep 17 00:00:00 2001 From: Torsten Date: Fri, 25 Mar 2022 21:31:52 +0200 Subject: [PATCH] basic roouter loop --- config/credentials.yml.enc | 2 +- lib/routers.rb | 52 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 lib/routers.rb diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index 71604d5..e3804d1 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -GaFVeuqp8OlAHTGhYbpuL3rjk2xbUYwxXtGsD+q2ebLlV1KU7/9et6ezxvS94pURH3NWfhJWY/M22oviWLl2o4pkpMSnHi7kIoDPjpeUG6ZQPgmwZgZtS+6o1/xiS5VtBq/auqEGucf8uxIa1+ZyUQGCF1V3cWNM9m+tNKo071jtN4JgsQ1NPfAUi7UfeIjy4/Tw1JbAwP2982AfioZqElDaqZdPiLHRvn0sKvAW8mjjFMUZQFWPcFOqDoZUQ381FJfhyhE0T2jJXb9ASzY8pNoH13GqEQhprbxGcFv4Sl0k+vobwy0yj/qdDbVTUpIJqsaJuY+yrdh7y4+Eyg873pbH8kHg37/kKckqPaCP2RIH06TBxtzPIwFEgHZcuZzY4KG8w64q7DDKr+XKRsjP7mjq9E8cYY3pQ4JB--0J9loPWEJu9xUa6C--K+TdTBkhMSUKxOkP9Zo4Xw== \ No newline at end of file +0m6IXDJDw8m1+jPTJ9S93WUkdsx4fO7FUa1SRuPdjrBZbweh9s4SJbVKfjJjlvSf4iqgtcFbcLCpHipGDFqRWwgainwYSgEQD0HpWuWpY4uLmJNi7xlOtukBSy3UHLdBagXMQX8bXnO8PrvepoEGKPbPOofvaeGw5C/l/zwaFpGow3eBxygMhdwbc9Ec5zgkvM/tse2zuzFjA5du6tg1D9M+co0yOBkee3lO88YStYgW54U15ClsT9d60ANDsR/nSuAGYUIGEdzYAxgnz26yP2y+HL0FW0ekv0070bawSWLxuPB9RWYv1VfVnX1JBYuUyOSd12sA6keQvm+yfsAqZe7GbkNIW1XUWol+crv4BJ9095bMafuP8p6zIPM++BOJ0yMBZYDAbq93Cd7+CvntuhcNddGqyMqHCTT/GaDTFrGx9z6uD//7WA==--gukSn6+4adNrpZau--ju1BA3I3U2uzjAFHR9XUSA== \ No newline at end of file diff --git a/lib/routers.rb b/lib/routers.rb new file mode 100644 index 0000000..4a8096c --- /dev/null +++ b/lib/routers.rb @@ -0,0 +1,52 @@ +require_relative "../config/application" +require "net/ssh" + +class Routers + + @@start_address = "10.20.20." + @@start_at = 30 + @@stop_at = 80 + + def initialize + @at = @@start_at + end + + def at + @@start_address + @at.to_s + end + + def for_each command_string + # find + # connect + # run command + end + + def all_ips + connections = {} + while(@at < @@stop_at) + error = nil + begin + connection = Net::SSH.start(at , "root" , + password: Rails.application.credentials.sala, + non_interactive: true , + timeout: 4) + puts "Ok #{at}" + connections[at] = connection + rescue Net::SSH::ConnectionTimeout + error = " Timed out ssh" + rescue Errno::ETIMEDOUT + error = " Timed out erro" + rescue Errno::EHOSTUNREACH + error = " Host unreachable" + rescue Errno::ECONNREFUSED + error = " Connection refused" + rescue Net::SSH::AuthenticationFailed + error = " Authentication failure" + end + puts "not at #{at} #{error}" if error + @at += 1 + end + end + +end +Routers.new.all_ips