Last active
June 17, 2016 00:14
-
-
Save hide1202/82a03ae3284b3e7ab1c39e4c9d2fab8c to your computer and use it in GitHub Desktop.
Domain Query 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
public static IPEndPoint QueryDns(string domain, short port) | |
{ | |
var domainAddresses = Dns.GetHostEntry(domain).AddressList; | |
foreach (var addr in domainAddresses) | |
{ | |
if (addr.AddressFamily == AddressFamily.InterNetwork) | |
{ | |
return new IPEndPoint(addr, port); | |
} | |
} | |
foreach (var addr in domainAddresses) | |
{ | |
if (addr.AddressFamily == AddressFamily.InterNetworkV6) | |
{ | |
return new IPEndPoint(addr, port); | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment