Little application to check if content of the file was manipulated

We needed some little server application to check periodically if  our website is not hacked and code inside is not changed in any way.

So we build this little utility, were application downloads source of our website and compare it with original file. If it spots any changes in code it will automatically sends email to alert us.

To make this application work you need to create a master file (master.html) and put it next to the exe file. In master file you put the content original content. You can easy change this source to check any text file not necessary web page.

SOURCE CODE:

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.IO;
 using System.Net;
 using System.Net.Mail;
namespace checkcode
 {
 class Program
 {
 static void Main(string[] args)
 {
 while (true)
 {
using (WebClient client = new WebClient()) // WebClient class inherits IDisposable
 {
 client.DownloadFile("http://www.yourwbesite.co.uk/index.html", @"index.html");
}
int i = 0, j = 0;
 FileStream fa1;
 FileStream fb2;
try
 {
 // open first file
 try
 {
 fa1 = new FileStream(@"master.html", FileMode.Open);
 }
 catch (FileNotFoundException exc)
 {
 Console.WriteLine(exc.Message);
 return;
 }
// open second file
 try
 {
 fb2 = new FileStream(@"index.html", FileMode.Open);
 }
 catch (FileNotFoundException exc)
 {
 Console.WriteLine(exc.Message);
 return;
 }
 }
 catch (IndexOutOfRangeException exc)
 {
 Console.WriteLine(exc.Message + "nUsage: CompFile f1 f2");
 return;
 }
// Compare files
 try
 {
 do
 {
 i = fa1.ReadByte();
 j = fb2.ReadByte();
 if (i != j) break;
 } while (i != -1 && j != -1);
 }
 catch (IOException exc)
 {
 Console.WriteLine(exc.Message);
 }
 if (i != j)
 {
 Console.WriteLine("Files differ.");
 try
 {
 MailMessage mail = new MailMessage();
 SmtpClient smtpC = new SmtpClient("smtp.gmail.com");
 //From address to send email
 mail.From = new MailAddress("alert@email.address.com");
 //To address to send email
 mail.To.Add("receiver@email.address.com");
 mail.Body = "URG CODE CHANGE!!!!!!!";
 mail.Subject = "ALERT URG.CO.UK CODE WAS CHANGED!!!!!";
 smtpC.Port = 587;
 //Credentials for From address
 smtpC.Credentials = new System.Net.NetworkCredential("username", "password");
 smtpC.EnableSsl = true;
 smtpC.Send(mail);
 Console.WriteLine("Message sent successfully");
System.Threading.Thread.Sleep(160000);
 }
 catch (Exception e)
 {
 Console.WriteLine(e.GetBaseException());
 Console.ReadLine();
 }
}
else
 {
Console.WriteLine("Files are the same.");
 }
fa1.Close();
 fb2.Close();
//Force garbage collection.
 GC.Collect();
// Wait for all finalizers to complete before continuing.
 GC.WaitForPendingFinalizers();
// Sleep for five seconds
 System.Threading.Thread.Sleep(60000);
}
 }
 }
 }