Guest User

Untitled

a guest
Jul 22nd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. require 'microtik'
  2.  
  3. EventMachine.run do
  4. client = Microtik.connect :host => "192.168.10.254", :port => 8728, :username => "admin", :password => "topsecret"
  5.  
  6. puts "Connecting..."
  7.  
  8. client.on_login_success do |client|
  9. puts "Login successful"
  10.  
  11. client.execute(client.command(:interface, :print).returning(:name, :bytes).where(:name => :leopard).on_reply do |reply|
  12. # Sum up the in and out counts
  13. bytes = reply.result(:bytes).split('/').collect { |n| n.to_i }.inject(0) { |i, n| i = i + n }
  14. puts "Interface '#{reply.result :name}' has transferred #{bytes / 1024.0 / 1024.0} MB"
  15. end)
  16.  
  17. client.execute(client.command(:system, :resource, :print).returning(:uptime).on_reply do |reply|
  18. puts "System uptime is #{reply.result :uptime}"
  19. end)
  20.  
  21. client.execute(client.command(:ip, 'dhcp-server', :lease, :getall).on_done do |replies|
  22. puts replies.collect { |reply| "IP '#{reply.result :address}' assigned to MAC #{reply.result('mac-address')}" }
  23. end)
  24.  
  25. client.on_pending_complete do |client|
  26. puts "All commands completed, closing session..."
  27. client.disconnect
  28. end
  29.  
  30. end
  31.  
  32. at_exit do
  33. client.disconnect
  34. puts "Disconnected from #{client.host}"
  35. end
  36.  
  37. end
Add Comment
Please, Sign In to add comment