获取dns中所有的ip


class Program
    {
        
static void Main(string[] args)
        {
            String strHostName;
            
if (args.Length == 0)
            {
                
// Getting Ip address of local machine

                
// First get the host name of local machine.               
                strHostName = Dns.GetHostName();
                Console.WriteLine(
"Local Machine's Host Name: " + strHostName);
                Console.ReadLine();
            }
            
else
            {
                strHostName 
= args[0];
            }

            
// Then using host name, get the IP address list..

            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());
            }
            Console.ReadLine();
            
//return 0;
        }
posted @ 2009-11-13 20:29  Sum_yang  阅读(627)  评论(0编辑  收藏  举报