Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: SrTrp en 27 Junio 2020, 02:36 am



Título: Como puedo revertir este codigo
Publicado por: SrTrp en 27 Junio 2020, 02:36 am
Bueno esta viendo unos ejemplos de c# y por accidente ejecute este que me cambia la ip local la máscara y la puerta, pero ahora ya no tengo acceso a Internet después que ejecute este codigo en mi los, intente reestablecer con CMD usando el comando ipconfig/release pero me dice que "no se puede realizar ninguna operacion...."
Y quisiera saber como revertir esto
Código
  1. string IPAddress = "192.168.1.101";
  2.            string SubnetMask = "255.255.255.0";
  3.            string Gateway = "192.168.1.254";
  4.            ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
  5.            ManagementObjectCollection objMOC = objMC.GetInstances();
  6.  
  7.            foreach (ManagementObject objMO in objMOC)
  8.            {
  9.                if (!(bool)objMO["IPEnabled"])
  10.                    continue;
  11.  
  12.                try
  13.                {
  14.                    ManagementBaseObject objNewIP = null;
  15.                    ManagementBaseObject objSetIP = null;
  16.                    ManagementBaseObject objNewGate = null;
  17.                    objNewIP = objMO.GetMethodParameters("EnableStatic");
  18.                    objNewGate = objMO.GetMethodParameters("SetGateways");
  19.  
  20.                    objNewGate["DefaultIPGateway"] = new string[] { Gateway };
  21.                    objNewGate["GatewayCostMetric"] = new int[] { 1 };
  22.                    objNewIP["IPAddress"] = new string[] { IPAddress };
  23.                    objNewIP["SubnetMask"] = new string[] { SubnetMask };
  24.                    objSetIP = objMO.InvokeMethod("EnableStatic", objNewIP, null);
  25.                    objSetIP = objMO.InvokeMethod("SetGateways", objNewGate, null);
  26.  
  27.                    MessageBox.Show("Updated IPAddress, SubnetMask and Default Gateway!");
  28.                }
  29.                catch (Exception ex)
  30.                {
  31.                    MessageBox.Show("Unable to Set IP : " + ex.Message);
  32.  
  33.                }
  34.  
  35.  


Título: Re: Como puedo revertir este codigo
Publicado por: FFernandez en 1 Julio 2020, 09:51 am
1º Seleciona el icono de red con el boton derecho (abrir configuracion de red y internet)
2º seleciona Ethernet
3º seleciona la red....1,2,


4º abajo puede configurar la ip, ponla en automatico