Skip to content

Instantly share code, notes, and snippets.

@yaasita
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaasita/564f80a8b67b26c628e1 to your computer and use it in GitHub Desktop.
Save yaasita/564f80a8b67b26c628e1 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
# dnsだけ調べる
# usage
# ./check_dns.sh hoge@example.com
domain=`echo $1 | cut -d@ -f2`
mxrecords=`dig +short $domain. mx | wc -l`
if [ "$mxrecords" -ge "1" ];then
echo ok
else
echo not found
fi
#!/usr/bin/env ruby
#
# = Email Ping
#
# Check to see if an email address exists by looking up MX records and connecting
# to the address's home SMTP server. It then starts to send a message to the address
# but quits before the message is actually sent.
require 'resolv'
require 'net/smtp'
address = ARGV[0].chomp
domain = address.split('@').last
dns = Resolv::DNS.new
mx_records = dns.getresources domain, Resolv::DNS::Resource::IN::MX
mx_server = mx_records.first.exchange.to_s
Net::SMTP.start mx_server, 25 do |smtp|
smtp.helo "loldomain.com"
smtp.mailfrom "test@loldomain.com"
begin
smtp.rcptto address
puts "#{address} => OK"
rescue Net::SMTPFatalError => err
puts "#{address} => NG"
end
end
# vim: set ft=ruby ts=2 sw=2 :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment