| Date: | Wed, 6 May 2009 09:39:00 -0700 |
| Reply-To: | "Andrew Z." <ahz001@GMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "Andrew Z." <ahz001@GMAIL.COM> |
| Organization: | http://groups.google.com |
| Subject: | Validating DNS MX records / Reading from pipe |
|
| Content-Type: | text/plain; charset=ISO-8859-1 |
This working code shows how to validate domain names (already
extracted from email addresses) by checking whether each has a valid
DNS MX record (meaning the domain can be e-mailed) with SAS 9.1 and
Windows XP. It demonstrates how to read stdout and stderr via a pipe.
It's based off this code: [1]
http://groups.google.com/group/comp.soft-sys.sas/browse_thread/thread/c619fb273134b14a/39307e1fb1e80fff?lnk=gst&q=nslookup#39307e1fb1e80fff
data dom;
INFILE DATALINES;
INPUT domain $1-15;
DATALINES;
yahoo.com
earthlink.net
sbcglobal.net
dfdsfgsd.com
;;;;
run;
data dnsmx;
set dom;
length command $100;
error=0;
good=0;
COMMAND = 'NSLOOKUP -type=mx -retry=3 -timeout=5 '||domain||' 2>&1';
EOP = 0;
INFILE NSLOOKUP PIPE FILEVAR=COMMAND END=EOP;
DO UNTIL (EOP);
INPUT;
PUT _INFILE_; /* for debugging */
if (index(_INFILE_, 'MX preference') > 0)
or (index(_INFILE_, 'internet address') > 0) then good=1;
if (index(_INFILE_, '***') > 0) then error=1;
END;
RUN;
Andrew
|