Advertisement
Guest User

Untitled

a guest
Aug 5th, 2017
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Net.NetworkInformation;
  7. using System.IO;
  8. using System.Net.Mail;
  9. using System.Net.Mime;
  10. using System.Diagnostics;
  11. using System.Reflection;
  12. using System.Management;
  13.  
  14.  
  15. namespace Windows_Monitor
  16. {
  17.     public class Functions
  18.     {
  19.         System.Diagnostics.PerformanceCounter cpuCounter;
  20.         System.Diagnostics.PerformanceCounter ramCounter;
  21.         /* Send Email */
  22.         public void MailSender()
  23.         {
  24.             System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
  25.             string user = "disparoautomatico@gatosabido.com";
  26.             string pass = "new1234";
  27.             System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
  28.             mail.From = new System.Net.Mail.MailAddress("alertas@gatosabido.com");
  29.             mail.To.Add("marcus.siqueira@gatosabido.com");
  30.             mail.Bcc.Add("marcus.siqueira@gatosabido.com");
  31.             mail.Subject = "[BOT] Monitoramento DRM - " + DateTime.Now.ToString("dd/MM/yyyy");
  32.             mail.IsBodyHtml = true;
  33.             mail.Body = "Envio de Email do DRM";
  34.             System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
  35.             System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(user, pass);
  36.             smtp.Credentials = credentials;
  37.             smtp.Send(mail);
  38.         }
  39.         /* Send Email With a File Attached */
  40.         public void AttachmentMail()
  41.         {
  42.             string user = "disparoautomatico@gatosabido.com";
  43.             string pass = "new1234";
  44.             MailMessage mail = new MailMessage();
  45.             mail.From = new MailAddress("marcus.siqueira@gatosabido.com");
  46.             mail.To.Add("marcus.siqueira@gatosabido.com");
  47.             mail.Subject = "[BOT] Envio de Email com Anexo C# - " + DateTime.Now.ToString("dd/MM/yyyy");
  48.             mail.Body = "Content Body";
  49.             mail.Attachments.Add(new Attachment("DRM_Log.txt"));
  50.             System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
  51.             System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(user, pass);
  52.             smtp.Credentials = credentials;
  53.             smtp.Send(mail);
  54.         }
  55.         /* Message Shown after the Email is Sent */
  56.         public void MailSent()
  57.         {
  58.             MessageBox.Show("Email Enviado com Sucesso");
  59.         }
  60.         /* Create a Log File */
  61.         public void CreateLog()
  62.         {
  63.             TextWriter tw = new StreamWriter("DRM_Log.txt");
  64.             tw.WriteLine(DateTime.Now);
  65.             tw.Close();
  66.             MessageBox.Show("Arquivo Criado");  
  67.         }
  68.         public void ExecuteMonitoringProcess()
  69.         {
  70.             // Não é Botão
  71.             System.Diagnostics.Process proc = new System.Diagnostics.Process();
  72.             proc.EnableRaisingEvents = false;
  73.             proc.StartInfo.FileName = "netstat";
  74.             proc.Start();
  75.         }
  76.         public void NetStat()
  77.         {
  78.             IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
  79.             TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections();
  80.             if (File.Exists("NetStat_Log.txt") == false)
  81.             {
  82.                 TextWriter NetStatLog = new StreamWriter("NetStat_Log.txt", true);
  83.                 NetStatLog.WriteLine("Arquivo dia: " + DateTime.Now.ToString("dd/MM/yyyy") + "\r\n\r\n");
  84.                 foreach (TcpConnectionInformation info in tcpConnections)
  85.                 {
  86.                     NetStatLog.WriteLine("Remote : " + info.RemoteEndPoint.Address.ToString()
  87.                     + ":" + info.RemoteEndPoint.Port.ToString()
  88.                     + "  ---> State  :   " + info.State.ToString());
  89.                 }
  90.                 NetStatLog.Close();
  91.             }
  92.             else
  93.             {
  94.                 TextWriter NetStatLog = new StreamWriter("NetStat_Log.txt", true);
  95.                 NetStatLog.WriteLine("\r\n\r\nArquivo dia: " + DateTime.Now.ToString("dd/MM/yyyy") + "\r\n\r\n");
  96.                 foreach (TcpConnectionInformation info in tcpConnections)
  97.                 {
  98.                     NetStatLog.WriteLine("Remote : " + info.RemoteEndPoint.Address.ToString()
  99.                     + ":" + info.RemoteEndPoint.Port.ToString()
  100.                     + "  ---> State  :   " + info.State.ToString());
  101.                 }
  102.                 NetStatLog.Close();
  103.             }
  104.         }
  105.         public void Memory()
  106.         {
  107.             PerformanceCounter cpuCounter = new System.Diagnostics.PerformanceCounter();
  108.             cpuCounter.CategoryName = "Processor";
  109.             cpuCounter.CounterName = "% Processor Time";
  110.             cpuCounter.InstanceName = "_Total";
  111.             PerformanceCounter ramCounter = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes");
  112.             TextWriter Hard = new StreamWriter("Hardware.txt");
  113.  
  114.             //Hard.WriteLine = (cpuCounter.NextValue() + "%");
  115.             //Hard.WriteLine = cpuCounter();
  116.             Hard.Close();
  117.             MessageBox.Show("Arquivo Criado");
  118.         }
  119.         public string getCurrentCpuUsage()
  120.         {
  121.             return cpuCounter.NextValue() + "%";
  122.         }
  123.         public string getAvailableRAM()
  124.         {
  125.             return ramCounter.NextValue() + "Mb";
  126.         }                  
  127.  
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement