0

*編集されたコード*これは私がこれまでに持っているものです。IPアドレスは、どのWebサイトに配置しても同じです。トピックのタイトルのすべてを解決するには、何をする必要がありますか?どうすればいいのかわからないので、助けてくれてありがとう!編集されたコード

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace CSDNS
{
    class Program
    {
        static void PrintHostInfo(String host)
        {
            {
                IPHostEntry hostinfo;

                try
                {
                    IPHostEntry hostInfo;

                    //Attempt to resolve DNS for given host or address
                    hostInfo = Dns.GetHostAddresses(host);

                    //Display the primary host name
                    Console.WriteLine("\tCanonical Name: " + hostInfo.HostName);

                    //Display list of IP addresses for this host
                    Console.WriteLine("\tIP Addresses:  ");
                    foreach (IPAddress ipaddr in hostInfo.AddressList)
                    {
                        Console.WriteLine("\t\t\t{0} ", ipaddr);
                    }
                    Console.WriteLine();

                    //Display list of alias names for this host
                    Console.Write("\tAliases:       ");
                    foreach (String alias in hostInfo.Aliases)
                    {
                        Console.Write(alias + " ");
                    }
                    Console.WriteLine("\n-------------------------------------\n\n");
                }
                catch (Exception)
                {
                    Console.WriteLine("\tUnable to resolve host: " + host + "\n");
                }
            }
        }

        static void Main()
        {
            //Get and print local host info
            try
            {
                Console.WriteLine("Local Host:");
                String localHostName = Dns.GetHostAddresses();
                Console.WriteLine("\tHost Name:      " + localHostName);

                PrintHostInfo(localHostName);
            }
            catch (Exception)
            {
                Console.WriteLine("Unable to resolve local host\n");
            }

            //Get and print info for hosts given on command line 
            foreach (String arg in new[] { "www.sunybroome.edu" })
            {
                Console.WriteLine(arg + ":");
                PrintHostInfo(arg);
            }
        }
    }
}
4

1 に答える 1

0
    static void PrintHostInfo(String host)
    {
        {
            IPHostEntry hostinfo;

            try
            {
                //Attempt to resolve DNS for given host or address
                IPAddress[] hostInfo = Dns.GetHostAddresses(host);

                //Display list of IP addresses for this host
                Console.WriteLine("\tIP Addresses:  ");
                foreach (IPAddress ipaddr in hostInfo)
                {
                    Console.WriteLine("\t\t\t{0} ", ipaddr);
                }

                Console.WriteLine("\n-------------------------------------\n\n");
            }
            catch (Exception)
            {
                Console.WriteLine("\tUnable to resolve host: " + host + "\n");
            }
        }
    }

    static void Main()
    {
        //Get and print local host info
        try
        {
            Console.WriteLine("Local Host:");
            String localHostName = Dns.GetHostAddresses("localhost")[0].ToString();
            Console.WriteLine("\tHost Name:      " + localHostName);

            PrintHostInfo(localHostName);
        }
        catch (Exception)
        {
            Console.WriteLine("Unable to resolve local host\n");
        }

        //Get and print info for hosts given on command line 
        foreach (String arg in new[] { "www.sunybroome.edu" })
        {
            Console.WriteLine(arg + ":");
            PrintHostInfo(arg);
        }
    }
于 2013-02-17T20:49:38.720 に答える