ASP.net中的网络IP列表 [英] Network IP List in ASP.net

查看:35
本文介绍了ASP.net中的网络IP列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在寻找将与网络连接的计算机与在Web应用程序中在该IP地址上创建的所有子网掩码一起扫描的系统,

我有一个使用Ping方法在控制台应用程序中列出我的代码,但是该方法在Web应用程序中不起作用,因此需要一些帮助.

这是控制台代码

hi to all,

I am Looking to scan a network connected computer to my system along with all subnet mask created on that IP address in web application,

I have a code that give me a list in console application using Ping method but that method does not work in web application, so need some help.

Here is console Code

class Program
    {
        
        static int upCount = 0;
        static object lockObj = new object();
        const bool resolveNames = true;

        static void Main(string[] args)
        {
        
            Stopwatch sw = new Stopwatch();
            sw.Start();
            string ipBase = "192.168.1.";
            for (int i = 1; i < 255; i++)
            {
                string ip = ipBase + i.ToString();

                Ping p = new Ping();
                p.PingCompleted += new PingCompletedEventHandler(p_PingCompleted);
        
                p.SendAsync(ip, 100, ip);
            }
        
            sw.Stop();
            TimeSpan span = new TimeSpan(sw.ElapsedTicks);
            Console.WriteLine("Took {0} milliseconds. {1} hosts active.", sw.ElapsedMilliseconds, upCount);
            Console.ReadLine();
        }

        static void p_PingCompleted(object sender, PingCompletedEventArgs e)
        {
            string ip = (string)e.UserState;
            if (e.Reply != null && e.Reply.Status == IPStatus.Success)
            {
                if (resolveNames)
                {
                    string name;
                    try
                    {
                        IPHostEntry hostEntry = Dns.GetHostEntry(ip);
                        name = hostEntry.HostName;
                    }
                    catch (SocketException ex)
                    {
                        name = "?";
                    }
                    Console.WriteLine("{0} ({1}) is up: ({2} ms)", ip, name, e.Reply.RoundtripTime);
                }
                else
                {
                    Console.WriteLine("{0} is up: ({1} ms)", ip, e.Reply.RoundtripTime);
                }
                lock (lockObj)
                {
                    upCount++;
                }
            }
            else if (e.Reply == null)
            {
                Console.WriteLine("Pinging {0} failed. (Null Reply object?)", ip);
            }

        }
    }




谢谢
Amit




Thanks
Amit

推荐答案

为什么要使用ping方法扫描所有IP地址,
请参阅以下代码,这将对您有所帮助

Why you are using the ping method to scan all IP address,
see the below code, this will help you

IPHostEntry ipEntry = DNS.GetHostByName (strHostName);
         IPAddress [] addr = ipEntry.AddressList;

         for (int i = 0; i < addr.Length; i++)
         {
             Console.WriteLine ("IP Address {0}: {1} ", i, addr[i].ToString ());
         }



参见此链接 [



See this Link[^] also.

Thanks


谢谢,我已经找到了解决方案,非常感谢您的发帖.
Thanks to all, I got the solution for it, thanks a lot for postings.


这篇关于ASP.net中的网络IP列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆