Obtener nombre de Equipo remoto en intranet partir de IP

28 views
Skip to first unread message

Carlos Admirador

unread,
May 22, 2019, 11:23:20 AM5/22/19
to AltNet-Hispano
HOla gente!!

Para obtener el nombre de equipo, por IP


 public static bool IsMachineOnline(string IP)
        {
            bool retVal = false;
            var scope = new ManagementScope(string.Format(@"\\{0}\root\cimv2", IP));
            var os = new ManagementClass(scope, new ManagementPath("Win32_OperatingSystem"), null);
            try
            {
                ManagementObjectCollection instances = os.GetInstances();
                retVal = true;
            }
            catch (Exception ex)
            {
                retVal = false;
                Console.WriteLine(ex.Message);
            }
            return retVal;
        }


Con WMI obtengo este error:

Error en la llamada a procedimiento remoto y no se ha ejecutado. (Excepción de HRESULT: 0x800706BF)


Sugerencias?
GRacias

Saludos gente!!!

Carlos Admirador

unread,
May 22, 2019, 11:27:53 AM5/22/19
to AltNet-Hispano
Ping es OK

  public static bool PingHost(string nameOrAddress)
        {
            bool pingable = false;
            Ping pinger = null;
            try
            {
                pinger = new Ping();
                PingReply reply = pinger.Send(nameOrAddress);
                pingable = reply.Status == IPStatus.Success;
            }
            catch (PingException)
            {
                // Discard PingExceptions and return false;
            }
            finally
            {
                if (pinger != null)
                {
                    pinger.Dispose();
                }
            }
            return pingable;
        }


  public static bool IsMachineUp(string IP)
        {
            bool retVal = false;
            try
            {
                Ping pingSender = new Ping();
                PingOptions options = new PingOptions();
                // Use the default Ttl value which is 128,
                // but change the fragmentation behavior.
                options.DontFragment = true;
                // Create a buffer of 32 bytes of data to be transmitted.
                string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
                byte[] buffer = Encoding.ASCII.GetBytes(data);
                int timeout = 120;
                PingReply reply = pingSender.Send(IP, timeout, buffer, options);
                if (reply.Status == IPStatus.Success)
                {

Carlos Admirador

unread,
May 22, 2019, 11:30:10 AM5/22/19
to AltNet-Hispano
Con DNS.HostEntry falla:


  public static string GetNameByIpAddress(string ip)
        {
            try
            {
                var e = System.Net.Dns.GetHostEntry(ip);
                //System.Net.Dns.GetHostByAddress(ip);
                return e.HostName;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                // Discard PingExceptions and return false;
                return null;
            }
        }
//        Points to Consider
//This DNS class will only work on the internal network.You cannot give any public address on the internet.
//If you connected to any VPN network and run this application.You will see multiple IP addresses returned.
        public static string GetMachineNameFromIPAddress(string ipAdress)
        {
            string machineName = null; // string.Empty;
            try
            {
                System.Net.IPHostEntry hostEntry = System.Net.Dns.GetHostEntry(ipAdress);
                machineName = hostEntry.HostName;
            }
            catch (Exception ex)
            {
                //log here
            }
            return machineName;
        }

Carlos Admirador

unread,
May 22, 2019, 11:39:52 AM5/22/19
to AltNet-Hispano
Comandos de Red:

C:\Users\zzz>getmac /s 10.50.101.82
Error: Error en la llamada a procedimiento remoto.


C:\Users\zzz>arp -a 10.50.101.82
No se encontraron entradas ARP.

Carlos Admirador

unread,
May 22, 2019, 4:05:24 PM5/22/19
to AltNet-Hispano
 Con la herramienta DameWare si accedo al equipo por la IP.

Carlos Admirador

unread,
May 22, 2019, 5:24:15 PM5/22/19
to AltNet-Hispano
El equipo destino tiene 2 IPs, dos adaptadores de red con IP, uno de ellos la tarjeta de red, y elotro creado por Wireshark (ncap).
Reply all
Reply to author
Forward
0 new messages