C # Query IP addresses by domain name (Enter CMD command parameters or start the program before entering the query)

Source: Internet
Author: User

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;namespace IPSearch{    class Program    {        static void Main(string[] args)        {            string www = "";            if (args.Length > 0)            {                www = args[0];                if (string.IsNullOrEmpty(www) || string.IsNullOrWhiteSpace(www))                {                    Console.WriteLine("Input is empty!");                    www = inputWWW();                }            }            else            {                www = inputWWW();            }            Console.WriteLine("Search...");            while (true)            {                                             IPAddress[] ipAddresses = null;                try                {                    ipAddresses = Dns.GetHostAddresses(formatWWW(www));//Important.                }                catch (System.Exception ex)                {                    Console.WriteLine(ex.Message);                    www = inputWWW();                    continue;                }                foreach (IPAddress ipAddress in ipAddresses)                {                                        Console.WriteLine(ipAddress.ToString());                }                Console.WriteLine("Search Completed!");                Console.WriteLine("Q:Quit.Other key:Continue.");                www = Console.ReadLine();                if (www.ToUpper().Equals("Q"))                {                    break;                }                else                {                    www = inputWWW();                }                            }                   }        private static string inputWWW()        {            Console.WriteLine("Input www");            string www = Console.ReadLine();            if (string.IsNullOrEmpty(www) || string.IsNullOrWhiteSpace(www))            {                Console.WriteLine("Input is empty!If you want to exit,please input Q!");                www = Console.ReadLine();                if (www.ToUpper().Equals("Q"))                {                    Environment.Exit(1);                }                www = inputWWW();                           }              return www;        }        private static string formatWWW(string www)        {            if (string.IsNullOrEmpty(www) || string.IsNullOrWhiteSpace(www))            {                return "";            }            string newWWW = www.ToUpper().Replace("HTTP://", "");            newWWW = newWWW.Split('/')[0];            return newWWW;        }    }}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.