Created
May 6, 2010 15:54
-
-
Save cloudvoxcode/392285 to your computer and use it in GitHub Desktop.
Asterisk AMI event listener - connect, read, & output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# connect to Asterisk AMI port, authenticate, and print all AMI event messages | |
# as they're received. | |
# more or for Asterisk hosting: http://help.cloudvox.com/ | |
# version: 2010-05-04 | |
require 'socket' | |
unless ARGV.length == 4 | |
puts 'usage: ruby ./ami_listener.rb hostname port username password' | |
puts 'example: ruby ./ami_listener.rb ami.cloudvox.com 12345 manager ubers3kr3t' | |
exit(2) | |
end | |
begin | |
t = TCPSocket.new(ARGV[0], ARGV[1]) | |
rescue | |
puts "Could not connect: #{$!}" | |
exit(3) | |
end | |
# banner | |
puts t.gets | |
t.print "Action: login\r\nUsername: #{ARGV[2]}\r\nSecret: #{ARGV[3]}\r\n\r\n" | |
while true | |
puts t.gets | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment