#!/usr/bin/expect # @(#)mtaprobe.exp 06 NOV 1998 Rob Thomas robt@cymru.com # A script to probe the SMTP daemon (port 25 TCP) for version, expn, and # e-mail relay capabilities. # # Usage: mtaprobe.exp [timeout], where is a # columnar list of host names or IP address, and [timeout] is an # optional timeout value, in seconds. The default is 30 seconds. # # You MUST replace with a legitimate e-mail # address if you wish to test relay capabilities. # ## main set inpfile [lindex $argv 0] set timeo [lindex $argv 1] # Check for enough args, display usage if we don't have enough. if 0==$argc { send_user "mtaprobe.exp: usage: mtaprobe.exp \[timeout\]\n" send_user "\nWhere is a columnar list of hostnames or IP\n" send_user "addresses, and \[timeout\] is an optional timeout value, in\n" send_user "seconds.\n" exit 1 } # Set the optional timeout value, in seconds. Default is 30 seconds. if {![string compare $timeo ""]} { set timeout 30 } else { set timeout $timeo } # See if we can open the input file if [catch {open $inpfile} fh] { puts "$fh" exit 1 } while {[gets $fh hostie] != -1} { send_user "mtaprobe $hostie: beginning...\n" spawn telnet $hostie 25 expect "2?: *" { send_user "mtaprobe $hostie: connect failed\n" continue } "2?? *" { send_user "mtaprobe $hostie: connect OK\n" } "refused" { send_user "mtaprobe $hostie: connect refused\n" continue } "closed" { send_user "mtaprobe $hostie: connect closed\n" continue } timeout { send_user "mtaprobe $hostie: connect to port 25 timeout\n" continue } send_user "mtaprobe $hostie: $expect_out(0,string)\n" send "helo foo.com\n" expect "Hello" { send_user "mtaprobe $hostie: helo OK\n" } "5??" { send_user "mtaprobe $hostie: helo FAILED\n" } timeout { send_user "mtaprobe $hostie: helo timeout\n" } send "expn root\n" expect "2?? " { send_user "mtaprobe $hostie: expn ENABLED\n" } "5??" { send_user "mtaprobe $hostie: expn DENIED\n" } timeout { send_user "mtaprobe $hostie: relay test timeout\n" } send "mail from: foo@cow.com\n" expect "2?? " { send "rcpt to: \n" expect "2?? " { send_user "mtaprobe $hostie: mail relay ENABLED\n" } "5??" { send_user "mtaprobe $hostie: mail relay DENIED\n" } timeout { send_user "mtaprobe $hostie: mail relay timeout\n" } } "5??" { send_user "mtaprobe $hostie: mail relay test failed\n" } timeout { send_user "mtaprobe $hostie: mail relay timeout\n" } send "quit\n" send_user "mtaprobe $hostie: completed.\n\n" } close $fh exit ## FINI