Example #1
0
 /*
  * Verifies a top-level domain exists against a fixed database.
  * The first argument supplies is either a domain name, or a TLD,
  * which is verified for validity against a fixed database that
  * has been previously obtained with the {@link #refreshTldDB()} method.
  * The second argument is the filename where the cache is stored.
  * The file format should be the same as  the one IANA publish at (http://data.iana.org/TLD/tlds-alpha-by-domain.txt).
  * The version in the first line will be check against the current cache version to prevent loading of old data.
  *
  * @param domainName    The domain name or a TLD to validate
  * @param cacheFilePath The full path to where the cache is stored.
  * @return <code>true</code> if the top-leve domain exist <code>false</code>
  * @throws TLDVerifyException
  */
 public bool verifyTldOffline(string domainName, string cacheFilePath)
 {
     try
     {
         string topLevelDomain = new DomainNameUtil().getTopLevelDomain(domainName);
         readTld(new FileInfo(cacheFilePath));
         return(cache.exist(topLevelDomain));
     }
     catch (IOException e)
     {
         throw new TLDVerifyException(e);
     }
 }
Example #2
0
 /*
  * Verifies a top-level domain exists.
  * This overloaded method takes from one to three arguments and verifies the TLD using the DNS protocol.
  *
  * @param domainName -- a domain name or a TLD.
  * @param QTypes -- the type of query (SOA, NS, etc.).
  * @param SendBy -- the method of query. Either UDP or TCP.
  * @return <code>true</code> if the top-level domain exists, <code>false</code> if it does not exist.
  */
 public bool verifyTld(string domainName)
 {
     try
     {
         string topLevelDomain = new DomainNameUtil().getTopLevelDomain(domainName);
         Lookup lookup         = new Lookup(topLevelDomain, QTypes.SOA, SendBy.UDP);
         return(lookup.Result());
     }
     catch (Exception e)
     {
         throw new TLDVerifyException(e.Message, e);
     }
 }
Example #3
0
        /*
         * Verifies a top-level domain exists against a fixed database.
         * This methods takes a single argument, which can either be a
         * domain name, or a TLD and verified for validity against a fixed database that
         * has been previously obtained with the {@link #refreshTldDB()} method.
         *
         * @param domainName the domain name or a TLD to validate
         * @return <code>true</code> if the top-leve domain exist <code>false</code>
         * @throws TLDVerifyException
         */

        public bool verifyTldOffline(string domainName)
        {
            try
            {
                string topLevelDomain = new DomainNameUtil().getTopLevelDomain(domainName);
                if (cache != null)
                {
                    return(cache.exist(topLevelDomain));
                }
                else
                {
                    refreshTldDB(TLD_CACHE_FILE);
                    return(verifyTldOffline(topLevelDomain, TLD_CACHE_FILE));
                }
            }
            catch (Exception e)
            {
                throw new TLDVerifyException(e);
            }
        }
Example #4
0
 public void testGetTopLevelDomain()
 {
     try
     {
         string tld = new DomainNameUtil().getTopLevelDomain("icann.org");
         assert.assertEquals("org", tld);
         tld = new DomainNameUtil().getTopLevelDomain("icann.org.");
         assert.assertEquals("org", tld);
         tld = new DomainNameUtil().getTopLevelDomain(".icann.org.");
         assert.assertEquals("org", tld);
         tld = new DomainNameUtil().getTopLevelDomain(".org.");
         assert.assertEquals("org", tld);
         tld = new DomainNameUtil().getTopLevelDomain("org");
         assert.assertEquals("org", tld);
     }
     catch (Exception e)
     {
         throw new TLDVerifyException(e);
     }
 }
Example #5
0
 public void testGetTopLevelDomain()
 {
     try
     {
         string tld = new DomainNameUtil().getTopLevelDomain("icann.org");
         assert.assertEquals("org", tld);
         tld = new DomainNameUtil().getTopLevelDomain("icann.org.");
         assert.assertEquals("org", tld);
         tld = new DomainNameUtil().getTopLevelDomain(".icann.org.");
         assert.assertEquals("org", tld);
         tld = new DomainNameUtil().getTopLevelDomain(".org.");
         assert.assertEquals("org", tld);
         tld = new DomainNameUtil().getTopLevelDomain("org");
         assert.assertEquals("org", tld);
     }
     catch (Exception e)
     {
         throw new TLDVerifyException(e);
     }
 }
Example #6
0
 /*
  * Verifies a top-level domain exists against a fixed database.
  * The first argument supplies is either a domain name, or a TLD,
  * which is verified for validity against a fixed database that
  * has been previously obtained with the {@link #refreshTldDB()} method.
  * The second argument is the filename where the cache is stored.
  * The file format should be the same as  the one IANA publish at (http://data.iana.org/TLD/tlds-alpha-by-domain.txt).
  * The version in the first line will be check against the current cache version to prevent loading of old data.
  *
  * @param domainName    The domain name or a TLD to validate
  * @param cacheFilePath The full path to where the cache is stored.
  * @return <code>true</code> if the top-leve domain exist <code>false</code>
  * @throws TLDVerifyException
  */
 public bool verifyTldOffline(string domainName, string cacheFilePath)
 {
     try
     {
         string topLevelDomain = new DomainNameUtil().getTopLevelDomain(domainName);
         readTld(new FileInfo(cacheFilePath));
         return cache.exist(topLevelDomain);
     }
     catch (IOException e)
     {
         throw new TLDVerifyException(e);
     }
 }
Example #7
0
 /*
  * Verifies a top-level domain exists against a fixed database.
  * This methods takes a single argument, which can either be a
  * domain name, or a TLD and verified for validity against a fixed database that
  * has been previously obtained with the {@link #refreshTldDB()} method.
  *
  * @param domainName the domain name or a TLD to validate
  * @return <code>true</code> if the top-leve domain exist <code>false</code>
  * @throws TLDVerifyException
  */
 public bool verifyTldOffline(string domainName)
 {
     try
     {
         string topLevelDomain = new DomainNameUtil().getTopLevelDomain(domainName);
         if (cache != null)
         {
             return cache.exist(topLevelDomain);
         }
         else
         {
             refreshTldDB(TLD_CACHE_FILE);
             return verifyTldOffline(topLevelDomain, TLD_CACHE_FILE);
         }
     }
     catch (Exception e)
     {
         throw new TLDVerifyException(e);
     }
 }
Example #8
0
 /*
  * Verifies a top-level domain exists.
  * This overloaded method takes from one to three arguments and verifies the TLD using the DNS protocol.
  *
  * @param domainName -- a domain name or a TLD.
  * @param QTypes -- the type of query (SOA, NS, etc.).
  * @param SendBy -- the method of query. Either UDP or TCP.
  * @return <code>true</code> if the top-level domain exists, <code>false</code> if it does not exist.
  */
 public bool verifyTld(string domainName)
 {
     try
     {
         string topLevelDomain = new DomainNameUtil().getTopLevelDomain(domainName);
         Lookup lookup = new Lookup(topLevelDomain, QTypes.SOA, SendBy.UDP);
         return lookup.Result();
     }
     catch (Exception e)
     {
         throw new TLDVerifyException(e.Message, e);
     }
 }