OP 10 August, 2023 - 08:28 PM
Code:
static string randy()
{
string chars = "ABCDEF0123456789";
string windows = "26AE";
string result = "";
Random random = new Random();
result += chars[random.Next(chars.Length)];
result += windows[random.Next(windows.Length)];
for (int i = 0; i < 5; i++)
{
result += "-";
result += chars[random.Next(chars.Length)];
result += chars[random.Next(chars.Length)];
}
return result;
}
static void localac(string adapterId, bool enable = true)
{
string interfaceName = "Ethernet";
foreach (NetworkInterface i in NetworkInterface.GetAllNetworkInterfaces())
{
if (i.Id == adapterId)
{
interfaceName = i.Name;
break;
}
}
string control;
if (enable)
control = "enable";
else
control = "disable";
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("netsh", $"interface set interface \"{interfaceName}\" {control}");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
p.WaitForExit();
}
static bool SpoofMAC()
{
bool err = false;
using RegistryKey NetworkAdapters = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Class\\{4d36e972-e325-11ce-bfc1-08002be10318}");
foreach (string adapter in NetworkAdapters.GetSubKeyNames())
{
if (adapter != "Properties")
{
try
{
using RegistryKey NetworkAdapter = Registry.LocalMachine.OpenSubKey($"SYSTEM\\CurrentControlSet\\Control\\Class\\{{4d36e972-e325-11ce-bfc1-08002be10318}}\\{adapter}", true);
if (NetworkAdapter.GetValue("BusType") != null)
{
NetworkAdapter.SetValue("NetworkAddress", randy());
string adapterId = NetworkAdapter.GetValue("NetCfgInstanceId").ToString();
localac(adapterId, false);
localac(adapterId, true);
}
}
catch (System.Security.SecurityException ex)
{
Console.WriteLine("\nyou need admin perms.");
err = true;
break;
}
}
}
return err;
}