中国开发网: 论坛: 程序员情感CBD: 贴子 474990
Miracle
测试again
[CODE=C#] using System; using System.Collections; using System.Net; using Bdev.Net; using Bdev.Net.Dns; using System.Data; using System.Data.SqlClient; using Bullseye.SystemFX; using System.IO; using System.Configuration; namespace MXLookup { /// /// Summary description for Class1. /// class Class1 { private static int E_Total = 0;//total emailcap email private static int R_Total = 0;//total reg email private static int E_V_Total = 0;//total valid emailcao email private static int R_V_Total = 0;//total valid reg email private static Hashtable ValidatedDomains = new Hashtable(); private static Hashtable BadDomains = new Hashtable(); /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { // read DNS settings IPAddress dnsServerAddress = IPAddress.Parse(ConfigurationSettings.AppSettings["DNS"]); // Retrieve the MX records for each domain SqlDataReader sdr = SQLManager.ExecuteReader( DataBaseType.BELogsDB, CommandType.Text, "select email, regpageType from MXLOOKUP_TEST_SAMPLE with (nolock) where email is not null"); try { while(sdr.Read()) { try { bool isReg = (bool)sdr["regpageType"]; string email = (string)sdr["email"]; if(isReg) { R_Total ++; } else { E_Total ++; } int index = email.IndexOf("@"); if(index != -1) { string domainName = email.Substring(index + 1, email.Length - index - 1); if(ValidatedDomains.ContainsKey(domainName.ToLower())) { ValidatedDomains[domainName.ToLower()] = ((int)(ValidatedDomains[domainName.ToLower()])) + 1; if(isReg) { R_V_Total ++; } else { E_V_Total ++; } } else { try { MXRecord[] records = Resolver.MXLookup(domainName, dnsServerAddress); if(records.Length > 0) { Console.WriteLine("VALID: " + domainName.ToLower()); ValidatedDomains[domainName.ToLower()] = 1; if(isReg) { R_V_Total ++; } else { E_V_Total ++; } } } catch(Exception e) { if(!BadDomains.ContainsKey(domainName.ToLower())) { Console.WriteLine("BAD: " + domainName.ToLower()); BadDomains[domainName.ToLower()] = 1; } else { BadDomains[domainName.ToLower()] = (int)BadDomains[domainName.ToLower()] + 1; } } } } } catch(Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); continue; } } } finally { sdr.Close(); } StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "result.txt"); try { sw.WriteLine("Total email (email capture): {0}", E_Total); sw.WriteLine("Total email (reg page): {0}", R_Total); sw.WriteLine("Total valid emai (email capture)l: {0}", E_V_Total); sw.WriteLine("Total valid email (reg page): {0}", R_V_Total); sw.WriteLine("Email cap valid rate: {0}%", E_V_Total/E_Total); sw.WriteLine("Reg page valid rate: {0}%", R_V_Total/R_Total); sw.WriteLine("Domains and valid emails of them:"); foreach(string domain in ValidatedDomains.Keys) { sw.WriteLine("{0}\t{1}", domain, ValidatedDomains[domain]); } sw.WriteLine("Bad domains and invalid emails of them:"); foreach(string domain in BadDomains.Keys) { sw.WriteLine("{0}\t{1}", domain, BadDomains[domain]); } } finally { sw.Close(); } } } } [/CODE]
夫习拳艺者,对已者十之七八,对人者,仅十之二三耳。拳艺之道,深无止境。得其浅者,一人敌,得其深者,何尝不万人敌耶!
我的Google Picasa相册
我的新BLOG

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录