using System; using System.Collections.Generic; using System.Text; using System.IO; using MySql.Data.MySqlClient; namespace WmHmailserverExporter { class Program { protected static string logPath = @"C:\Users\Willem L. Middelkoop\Documents\Visual Studio 2005\Projects\WmHmailserverExporter\WmHmailserverExporter\log"; protected static string userStart = "\"RECEIVED: USER "; protected static string userEnd = "\""; protected static string passStart = "\"RECEIVED: PASS "; protected static string passEnd = "\""; static void Main(string[] args) { Console.WriteLine("WmHMailServerExporter"); foreach (string logFile in Directory.GetFiles(logPath, "*.log")) { TextReader reader = (TextReader) File.OpenText(logFile); string logFileText = reader.ReadToEnd(); int iterator = 0; while (iterator >= 0) { iterator = logFileText.IndexOf(userStart, iterator); if (iterator >= 0) { string username = null; string password = null; getCredentials(logFileText, ref iterator, ref username, ref password); Console.WriteLine(username + " - " + password); } } reader.Close(); break; // one file for now } Console.ReadLine(); } protected static void getCredentials(string logFileText, ref int iterator, ref string username, ref string password) { username = Tools.getStringInBetween(userStart, userEnd, logFileText, ref iterator); password = Tools.getStringInBetween(passStart, passEnd, logFileText, ref iterator); } protected MySqlConnection getMySqlConnection() { #region connection string string connectionString = "server=localhost;" + "port=3306;" + "charset=utf8;" + "database=hmailserver;" + "uid=root;" + "pwd=YOUR_DB_PASSWORD;"; #endregion return new MySqlConnection(connectionString); } } }