From 57204630a6605e26ac2ed03d6d5886d51d6617c0 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Mon, 20 May 2013 16:25:48 +0100 Subject: The banner matching now copes with a string or a regexp. --- lib/custodian/protocoltest/tcp.rb | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'lib/custodian/protocoltest') diff --git a/lib/custodian/protocoltest/tcp.rb b/lib/custodian/protocoltest/tcp.rb index b4a23b2..e21e5a5 100644 --- a/lib/custodian/protocoltest/tcp.rb +++ b/lib/custodian/protocoltest/tcp.rb @@ -158,8 +158,10 @@ module Custodian read = socket.sysread(1024) if ( do_read ) # trim to a sane length & strip newlines. - read = read[0,255] unless ( read.nil? ) - read.gsub!(/[\n\r]/, "") unless ( read.nil? ) + if ( ! read.nil? ) + read = read[0,255] + read.gsub!(/[\n\r]/, "") + end socket.close() @@ -168,8 +170,19 @@ module Custodian return true else # test for banner - if ( ( !read.nil? ) && ( banner.match(read) ) ) - return true + + # regexp. + if ( banner.class == "Regexp" ) + if ( ( !read.nil? ) && ( banner.match(read) ) ) + return true + end + end + + # string. + if ( banner.class == "String" ) + if ( ( !read.nil? ) && ( read =~ /#{banner}/i ) ) + return true + end end @error = "We expected a banner matching '#{banner}' but we got '#{read}'" -- cgit v1.2.1