Created
July 9, 2016 04:38
-
-
Save define-private-public/a1d75859466569f3d857a391defa5ea5 to your computer and use it in GitHub Desktop.
Example of Dns Class usage in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Filename: DnsExample.cs | |
| // Author: Benjamin N. Summerton <define-private-public> | |
| // License: Unlicense (http://unlicense.org/) | |
| using System; | |
| using System.Net; | |
| namespace DnsExample | |
| { | |
| class DnsExample | |
| { | |
| public static string domain = "16bpp.net"; | |
| public static void Main(string[] args) | |
| { | |
| // Print a little info about us | |
| Console.WriteLine("Local Hostname: {0}", Dns.GetHostName()); | |
| Console.WriteLine(); | |
| // Get DNS info synchronously | |
| IPHostEntry hostInfo = Dns.GetHostEntry(domain); | |
| // Print aliases | |
| if (hostInfo.Aliases.Length > 0) | |
| { | |
| Console.WriteLine("Aliases for {0}:", hostInfo.HostName); | |
| foreach (string alias in hostInfo.Aliases) | |
| Console.WriteLine(" {0}", alias); | |
| Console.WriteLine(); | |
| } | |
| // Print IP addresses | |
| if (hostInfo.AddressList.Length > 0) | |
| { | |
| Console.WriteLine("IP Addresses for {0}", hostInfo.HostName); | |
| foreach(IPAddress addr in hostInfo.AddressList) | |
| Console.WriteLine(" {0}", addr); | |
| Console.WriteLine(); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment