Best way to determine if a domain name would be a valid in a “hosts” file?

前端 未结 2 532
时光说笑
时光说笑 2020-12-16 15:33

The Windows Hosts file allows you to associate an IP to a host name that has far greater freedom than a normal Internet domain name. I\'d like to create a function that dete

2条回答
  •  不知归路
    2020-12-16 16:10

    How about the System.Uri.CheckHostName() method?

    private static bool IsValidDomainName(string name)
    {
        return Uri.CheckHostName(name) != UriHostNameType.Unknown;
    }
    

    Why do the work yourself?

提交回复
热议问题