John,

I have a bit of Java code that I wrote for a client awhile ago that does
similar to what you are looking for.  I don't know if PHP has the equivalent
API set but thought I would share so you could see what I am accomplishing
with the code.  See the utility class below followed by a test class. (Note:
Load this in eclipse and run it in debug to see how it works)



....DomainRecord.java....
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;

import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;

public class DomainRecord {

    public static final String RECORD_SOA = "SOA";
    public static final String RECORD_A = "A";
    public static final String RECORD_NS = "NS";
    public static final String RECORD_MX = "MX";
    public static final String RECORD_CNAME = "CNAME";

    public static List lookup(String hostName, String record) {

        List result = new Vector();
        try {
            Hashtable env = new Hashtable();
            env.put("java.naming.factory.initial",
"com.sun.jndi.dns.DnsContextFactory");
            DirContext ictx = new InitialDirContext(env);
            Attributes attrs = ictx.getAttributes(hostName, new String[] {
record });
            Attribute attr = attrs.get(record);

            NamingEnumeration attrEnum = attr.getAll();
            while (attrEnum.hasMoreElements())
                result.add(attrEnum.next());
        } catch (NamingException e) {
            e.printStackTrace();
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
        return result;
    }
}

....TestDomainRecord.java....
import java.util.Iterator;
import java.util.List;

import com.mowyourlawn.util.DomainRecord;

public class TestDomainRecord {

    public static void main(String[] args) {
        printList(DomainRecord.lookup("mowyourlawn.com",
DomainRecord.RECORD_A));
        printList(DomainRecord.lookup("mowyourlawn.com",
DomainRecord.RECORD_MX));
        printList(DomainRecord.lookup("mowyourlawn.com",
DomainRecord.RECORD_NS));
        printList(DomainRecord.lookup("mowyourlawn.com",
DomainRecord.RECORD_SOA));
    }

    static void printList(List l) {
        Iterator iter = l.iterator();
        while (iter.hasNext()) {
            System.out.println(iter.next());
        }
    }
}

HTH,
Aaron Bartell
http://mowyourlawn.com

-----Original Message-----
From: web400-bounces@xxxxxxxxxxxx [mailto:web400-bounces@xxxxxxxxxxxx] On
Behalf Of Jon Paris
Sent: Wednesday, January 18, 2006 7:43 PM
To: web400
Subject: [WEB400] DNS Lookups

I am using a small PHP program to perform validation on e-mail domain names
using gethostbyname.

I found that some domains (e.g. xyz.com) gave false fails, so I adapted the
program to also try mail.xxx.xxx.  I'm still seeing failures on some
addresses that are supposed to be good.  Any ideas on what else to check?

Reason I need this is that sometimes I have to operate using an ISP that
rejects all recipients if any one of them fails a DNS lookup.  They don't
tell you _which_ one - so it can be a royal pain trying to isolate the
problem address.

Jon Paris
Partner400

www.Partner400.com
www.RPGWorld.com

--
This is the Web Enabling the AS400 / iSeries (WEB400) mailing list To post a
message email: WEB400@xxxxxxxxxxxx To subscribe, unsubscribe, or change list
options,
visit: http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/web400.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.