Skip to content

Instantly share code, notes, and snippets.

@bjhaid
Forked from askinss/ema.rb
Last active December 23, 2015 23:19
Show Gist options
  • Save bjhaid/6709319 to your computer and use it in GitHub Desktop.
Save bjhaid/6709319 to your computer and use it in GitHub Desktop.
require 'net/telnet'
def get_imsi(array_of_msisdns, &block)
ema = Net::Telnet::new("Host" => "#{HOST}",
"Port" => "#{PORT}",
"Timeout" => 10,
"Prompt" => /Enter command:/)
ema.cmd("LOGIN:#{USERNAME}:#{PASSWORD};")
ema.waitfor(/Enter command:/)
array_of_msisdns.each do |msisdn|
resp = ema.cmd("GET:HLRSUB:MSISDN,#{msisdn}:IMSI;")
puts resp
resp = resp.match(/RESP:(?<respcode>\d+):MSISDN,(?<msisdn>\d+):IMSI,(?<imsi>\d+);/)
block.call([resp[:msisdn], resp[:imsi]])
array_of_msisdns.shift
end
ema.close
end
msisdns = Array.new
f = File.open("/home/bblite/subscr.txt")
f.each_line {|line| msisdns << line.chomp}
retry_count = 3
File.open("/home/bblite/subscriber_query.sql", "ab") do |file|
begin
get_imsi msisdns
rescue
while retry_count > 0
get_imsi msisdns
retry_count = retry_count - 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment