Bug Fixed DNS Tests

This commit is contained in:
plane000
2018-05-14 17:40:03 +01:00
parent 1d5ff3daeb
commit c873e9e9b1

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
@@ -11,16 +12,19 @@ namespace Networking_Tools {
public string[] GetIPs() {
List<string> ipAddresses = new List<string>();
IPHostEntry iphost = Dns.GetHostEntry(HostName);
foreach (IPAddress theAddress in iphost.AddressList) {
if (theAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) {
ipAddresses.Add(theAddress.ToString());
try {
IPHostEntry iphost = Dns.GetHostEntry(HostName);
foreach (IPAddress theAddress in iphost.AddressList) {
if (theAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) {
ipAddresses.Add(theAddress.ToString());
}
}
} catch (SocketException) {
ipAddresses.Add("");
}
return ipAddresses.ToArray();
}
}
}