-
-
Save bjhaid/6709319 to your computer and use it in GitHub Desktop.
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
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