| iaxrecord.rb - warvox - VoIP based wardialing tool, forked from rapid7/warvox. | |
| git clone git://jay.scot/warvox | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| iaxrecord.rb (1969B) | |
| --- | |
| 1 #!/usr/bin/env ruby | |
| 2 | |
| 3 $:.unshift(::File.join(::File.dirname(__FILE__), "..", "lib")) | |
| 4 | |
| 5 | |
| 6 def stop | |
| 7 exit(0) | |
| 8 end | |
| 9 | |
| 10 trap("SIGINT") { stop() } | |
| 11 trap("SIGTERM") { stop() } | |
| 12 | |
| 13 require 'rubygems' | |
| 14 require "warvox/proto/iax2" | |
| 15 require "optparse" | |
| 16 | |
| 17 parser = OptionParser.new | |
| 18 opts = { | |
| 19 recording_time: 52 | |
| 20 } | |
| 21 | |
| 22 parser.banner = "Usage: #{$0} [options]" | |
| 23 parser.on("-s server") do |v| | |
| 24 opts[:server_host] = v | |
| 25 end | |
| 26 | |
| 27 parser.on("-u user") do |v| | |
| 28 opts[:username] = v | |
| 29 end | |
| 30 | |
| 31 parser.on("-p pass") do |v| | |
| 32 opts[:password] = v | |
| 33 end | |
| 34 | |
| 35 parser.on("-o output") do |v| | |
| 36 opts[:output] = v | |
| 37 end | |
| 38 | |
| 39 parser.on("-n number") do |v| | |
| 40 opts[:called_number] = v | |
| 41 end | |
| 42 | |
| 43 parser.on("-c cid") do |v| | |
| 44 opts[:caller_number] = v | |
| 45 end | |
| 46 | |
| 47 parser.on("-l seconds") do |v| | |
| 48 opts[:recording_time] = v.to_i | |
| 49 end | |
| 50 | |
| 51 parser.on("-d") do |v| | |
| 52 opts[:debugging] = true | |
| 53 end | |
| 54 | |
| 55 parser.on("-k keys") do |v| | |
| 56 opts[:sendkeys] = v | |
| 57 end | |
| 58 | |
| 59 parser.on("-h") do | |
| 60 $stderr.puts parser | |
| 61 exit(1) | |
| 62 end | |
| 63 | |
| 64 parser.parse!(ARGV) | |
| 65 | |
| 66 if not (opts[:server_host] and opts[:username] and opts[:password] and o… | |
| 67 $stderr.puts parser | |
| 68 exit(1) | |
| 69 end | |
| 70 | |
| 71 | |
| 72 cli = WarVOX::Proto::IAX2::Client.new(opts) | |
| 73 | |
| 74 reg = cli.create_call | |
| 75 r = reg.register | |
| 76 if not r | |
| 77 $stderr.puts "ERROR: Unable to register with the IAX server" | |
| 78 exit(0) | |
| 79 end | |
| 80 | |
| 81 c = cli.create_call | |
| 82 r = c.dial( opts[:called_number] ) | |
| 83 if not r | |
| 84 $stderr.puts "ERROR: Unable to dial the requested number" | |
| 85 exit(0) | |
| 86 end | |
| 87 | |
| 88 begin | |
| 89 | |
| 90 ::Timeout.timeout( opts[:recording_time] ) do | |
| 91 while (c.state != :hangup) | |
| 92 case c.state | |
| 93 when :ringing | |
| 94 when :answered | |
| 95 when :hangup | |
| 96 break | |
| 97 end | |
| 98 select(nil,nil,nil, 0.25) | |
| 99 end | |
| 100 end | |
| 101 rescue ::Timeout::Error | |
| 102 ensure | |
| 103 c.hangup rescue nil | |
| 104 end | |
| 105 | |
| 106 cli.shutdown | |
| 107 | |
| 108 cnt = 0 | |
| 109 fd = ::File.open( opts[:output], "wb") | |
| 110 c.each_audio_frame do |frame| | |
| 111 fd.write(frame) | |
| 112 cnt += frame.length | |
| 113 end | |
| 114 fd.close | |
| 115 | |
| 116 $stdout.puts "COMPLETED: BYTES=#{cnt} RINGTIME=#{c.ring_time} FILE=#{ ::… |