Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Net.NetworkInformation;
- using System.IO;
- using System.Net.Mail;
- using System.Net.Mime;
- using System.Diagnostics;
- using System.Reflection;
- using System.Management;
- namespace Windows_Monitor
- {
- public class Functions
- {
- System.Diagnostics.PerformanceCounter cpuCounter;
- System.Diagnostics.PerformanceCounter ramCounter;
- /* Send Email */
- public void MailSender()
- {
- System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
- string user = "disparoautomatico@gatosabido.com";
- string pass = "new1234";
- System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
- mail.From = new System.Net.Mail.MailAddress("alertas@gatosabido.com");
- mail.To.Add("marcus.siqueira@gatosabido.com");
- mail.Bcc.Add("marcus.siqueira@gatosabido.com");
- mail.Subject = "[BOT] Monitoramento DRM - " + DateTime.Now.ToString("dd/MM/yyyy");
- mail.IsBodyHtml = true;
- mail.Body = "Envio de Email do DRM";
- System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
- System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(user, pass);
- smtp.Credentials = credentials;
- smtp.Send(mail);
- }
- /* Send Email With a File Attached */
- public void AttachmentMail()
- {
- string user = "disparoautomatico@gatosabido.com";
- string pass = "new1234";
- MailMessage mail = new MailMessage();
- mail.From = new MailAddress("marcus.siqueira@gatosabido.com");
- mail.To.Add("marcus.siqueira@gatosabido.com");
- mail.Subject = "[BOT] Envio de Email com Anexo C# - " + DateTime.Now.ToString("dd/MM/yyyy");
- mail.Body = "Content Body";
- mail.Attachments.Add(new Attachment("DRM_Log.txt"));
- System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
- System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(user, pass);
- smtp.Credentials = credentials;
- smtp.Send(mail);
- }
- /* Message Shown after the Email is Sent */
- public void MailSent()
- {
- MessageBox.Show("Email Enviado com Sucesso");
- }
- /* Create a Log File */
- public void CreateLog()
- {
- TextWriter tw = new StreamWriter("DRM_Log.txt");
- tw.WriteLine(DateTime.Now);
- tw.Close();
- MessageBox.Show("Arquivo Criado");
- }
- public void ExecuteMonitoringProcess()
- {
- // Não é Botão
- System.Diagnostics.Process proc = new System.Diagnostics.Process();
- proc.EnableRaisingEvents = false;
- proc.StartInfo.FileName = "netstat";
- proc.Start();
- }
- public void NetStat()
- {
- IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
- TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections();
- if (File.Exists("NetStat_Log.txt") == false)
- {
- TextWriter NetStatLog = new StreamWriter("NetStat_Log.txt", true);
- NetStatLog.WriteLine("Arquivo dia: " + DateTime.Now.ToString("dd/MM/yyyy") + "\r\n\r\n");
- foreach (TcpConnectionInformation info in tcpConnections)
- {
- NetStatLog.WriteLine("Remote : " + info.RemoteEndPoint.Address.ToString()
- + ":" + info.RemoteEndPoint.Port.ToString()
- + " ---> State : " + info.State.ToString());
- }
- NetStatLog.Close();
- }
- else
- {
- TextWriter NetStatLog = new StreamWriter("NetStat_Log.txt", true);
- NetStatLog.WriteLine("\r\n\r\nArquivo dia: " + DateTime.Now.ToString("dd/MM/yyyy") + "\r\n\r\n");
- foreach (TcpConnectionInformation info in tcpConnections)
- {
- NetStatLog.WriteLine("Remote : " + info.RemoteEndPoint.Address.ToString()
- + ":" + info.RemoteEndPoint.Port.ToString()
- + " ---> State : " + info.State.ToString());
- }
- NetStatLog.Close();
- }
- }
- public void Memory()
- {
- PerformanceCounter cpuCounter = new System.Diagnostics.PerformanceCounter();
- cpuCounter.CategoryName = "Processor";
- cpuCounter.CounterName = "% Processor Time";
- cpuCounter.InstanceName = "_Total";
- PerformanceCounter ramCounter = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes");
- TextWriter Hard = new StreamWriter("Hardware.txt");
- //Hard.WriteLine = (cpuCounter.NextValue() + "%");
- //Hard.WriteLine = cpuCounter();
- Hard.Close();
- MessageBox.Show("Arquivo Criado");
- }
- public string getCurrentCpuUsage()
- {
- return cpuCounter.NextValue() + "%";
- }
- public string getAvailableRAM()
- {
- return ramCounter.NextValue() + "Mb";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement