Skip to content

Instantly share code, notes, and snippets.

@JamisonWhite
Created December 3, 2014 15:20
Show Gist options
  • Save JamisonWhite/4f4540b2af9d8f657dd2 to your computer and use it in GitHub Desktop.
Save JamisonWhite/4f4540b2af9d8f657dd2 to your computer and use it in GitHub Desktop.
Get all subdomains of a domain
/// <summary>
/// Get all labels of the domain. Item 0 is always TLD.
/// </summary>
/// <param name="domain"></param>
/// <returns></returns>
public static IEnumerable<string> GetDomainSubdomains(string domain)
{
var parts = domain.Split('.').ToArray();
var labels = new List<String>(parts.Length + 1);
for (var i = 0; i < parts.Length; i++)
{
labels.Add(String.Join(".", parts.Skip(i)));
}
return labels;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment