Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,I need to know name of the computer which is using a particular remote machine on network,using c#
Posted
Updated 24-Feb-15 23:16pm
v2

1 solution

i dont know is it useful for you but
you will get all the ip addresses of systems which are in network
using System.Net.NetworkInformation;
using System.Threading;
using System.Diagnostics;
using System.Collections.Generic;
using System;
 
namespace ConsoleApplication1
{
    class localipaddresses
    {
        private static List<ping> pingers = new List<ping>();
        private static int instances = 0;
 
        private static object @lock = new object();
 
        private static int result = 0;
        private static int timeOut = 250;
 
        private static int ttl = 5;
 
        public static void Main()
        {
            string baseIP = "192.168.0.";
 
            Console.WriteLine("Pinging 255 destinations of D-class in {0}*", baseIP);
 
            CreatePingers(255);
 
            PingOptions po = new PingOptions(ttl, true);
            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
            byte[] data = enc.GetBytes("abababababababababababababababab");
 
            SpinWait wait = new SpinWait();
            int cnt = 1;
 
            Stopwatch watch = Stopwatch.StartNew();
 
            foreach (Ping p in pingers)
            {
                lock (@lock)
                {
                    instances += 1;
                }
 
                p.SendAsync(string.Concat(baseIP, cnt.ToString()), timeOut, data, po);
                cnt += 1;
            }
 
            while (instances > 0)
            {
                wait.SpinOnce();
            }
 
            watch.Stop();
 
            DestroyPingers();
 
            Console.WriteLine("Finished in {0}. Found {1} active IP-addresses.", watch.Elapsed.ToString(), result);
            Console.ReadKey();
 
        }
 
        public static void Ping_completed(object s, PingCompletedEventArgs e)
        {
            lock (@lock)
            {
                instances -= 1;
            }
 
            if (e.Reply.Status == IPStatus.Success)
            {
                Console.WriteLine(string.Concat("Active IP: ", e.Reply.Address.ToString()));
                result += 1;
            }
            else
            {
                //Console.WriteLine(String.Concat("Non-active IP: ", e.Reply.Address.ToString()))
            }
        }
 
        private static void CreatePingers(int cnt)
        {
            for (int i = 1; i <= cnt; i++)
            {
                Ping p = new Ping();
                p.PingCompleted += Ping_completed;
                pingers.Add(p);
            }
        }
 
        private static void DestroyPingers()
        {
            foreach (Ping p in pingers)
            {
                p.PingCompleted -= Ping_completed;
                p.Dispose();
            }
            pingers.Clear();
        }
    }
}
</ping></ping>
 
Share this answer
 
v2
Comments
Maria Zacharias 25-Feb-15 5:14am    
Hi,I need to know name of the computer which is using a particular remote machine on network
Samatha Reddy G 25-Feb-15 5:24am    
k.that i dont know i will try and tell you, using this you can able to find only ip addresses
Maria Zacharias 25-Feb-15 23:01pm    
Thanks Samatha..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900