summaryrefslogtreecommitdiff
path: root/worker/tests/smtp.rb
diff options
context:
space:
mode:
Diffstat (limited to 'worker/tests/smtp.rb')
-rw-r--r--worker/tests/smtp.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/worker/tests/smtp.rb b/worker/tests/smtp.rb
new file mode 100644
index 0000000..66da545
--- /dev/null
+++ b/worker/tests/smtp.rb
@@ -0,0 +1,52 @@
+require 'timeout'
+
+
+#
+# Run an SMTP test.
+#
+#
+# Return value
+# TRUE: The host is up
+#
+# FALSE: The host is not up
+#
+def smtp_test ( params )
+
+ #
+ # Get the hostname & port to test against.
+ #
+ host = params['target_host']
+ port = 25
+
+ puts "SMTP testing host #{host}:#{port}"
+
+
+ begin
+ timeout(3) do
+
+ begin
+ socket = TCPSocket.new( host, port )
+ socket.puts( "QUIT\n\n")
+
+ banner = socket.gets(nil)
+ banner = banner[0,20]
+
+ socket.close()
+
+ if ( banner =~ /SMTP/i )
+ puts "SMTP alive: #{banner}"
+ return true
+ end
+ rescue
+ puts "SMTP exception on host #{host}:#{port} - #{$!}"
+ return false
+ end
+ end
+ rescue Timeout::Error => e
+
+ puts "SMTP TIMEOUT: #{e}"
+ return false
+ end
+ puts "SMTP Misc Failure"
+ return false
+end