Last active
August 29, 2015 14:03
-
-
Save yaasita/564f80a8b67b26c628e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# dnsだけ調べる | |
# usage | |
# ./check_dns.sh [email protected] | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "[email protected]" | |
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