Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'microtik'
- EventMachine.run do
- client = Microtik.connect :host => "192.168.10.254", :port => 8728, :username => "admin", :password => "topsecret"
- puts "Connecting..."
- client.on_login_success do |client|
- puts "Login successful"
- client.execute(client.command(:interface, :print).returning(:name, :bytes).where(:name => :leopard).on_reply do |reply|
- # Sum up the in and out counts
- bytes = reply.result(:bytes).split('/').collect { |n| n.to_i }.inject(0) { |i, n| i = i + n }
- puts "Interface '#{reply.result :name}' has transferred #{bytes / 1024.0 / 1024.0} MB"
- end)
- client.execute(client.command(:system, :resource, :print).returning(:uptime).on_reply do |reply|
- puts "System uptime is #{reply.result :uptime}"
- end)
- client.execute(client.command(:ip, 'dhcp-server', :lease, :getall).on_done do |replies|
- puts replies.collect { |reply| "IP '#{reply.result :address}' assigned to MAC #{reply.result('mac-address')}" }
- end)
- client.on_pending_complete do |client|
- puts "All commands completed, closing session..."
- client.disconnect
- end
- end
- at_exit do
- client.disconnect
- puts "Disconnected from #{client.host}"
- end
- end
Add Comment
Please, Sign In to add comment