bsm*_*moo 6 unix bash shell command telnet
我想知道电子邮件地址是否有效.
我通过telnet telnet完成了这个,见下文
$ telnet mail.example.com 25
Trying 0.0.0.0...
Connected to mail.example.com.
Escape character is '^]'.
220 mail.example.com Mon, 14 Jan 2013 19:01:44 +0000
helo email.com
250 mail.example.com Hello email.com [0.0.0.0]
mail from:blake@email.com
250 OK
rcpt to:gfdgsdfhgsfd@example.com
550 Unknown user
Run Code Online (Sandbox Code Playgroud)
有了这550个请求,我知道该地址在邮件服务器上无效......如果它有效,我会得到如下的响应:
250 2.1.5 OK
Run Code Online (Sandbox Code Playgroud)
我如何在shell脚本中自动执行此操作?到目前为止,我有以下内容
#!/bin/bash
host=`dig mx +short $1 | cut -d ' ' -f2 | head -1`
telnet $host 25
Run Code Online (Sandbox Code Playgroud)
谢谢!
试着这样做:
[[ $@ ]] || {
printf "Usage\n\t./$0 domain <email> <from_email> <rcpt_email>\n"
exit 1
}
{
sleep 1
echo "helo $2"
sleep 0.5
echo "mail from:$3"
sleep 0.5
echo "rcpt to:$4"
echo
} | telnet $1 25 |
grep -q "Unknown user" &&
echo "Invalid email" ||
echo "Valid email"
Run Code Online (Sandbox Code Playgroud)
用法:
./script.sh domain email from_email rcpt_email
Run Code Online (Sandbox Code Playgroud)