Updated
This commit is contained in:
parent
2dca7a7f4f
commit
2e302c1909
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
@ -1322,7 +1323,7 @@ namespace EonaCat.Network
|
||||||
return string.Format("{0}; {1}", m, parameters.ToString("; "));
|
return string.Format("{0}; {1}", m, parameters.ToString("; "));
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static System.Net.IPAddress ToIPAddress(this string value)
|
internal static System.Net.IPAddress ToIPAddress(this string value, bool useIPv6 = false)
|
||||||
{
|
{
|
||||||
if (value == null || value.Length == 0)
|
if (value == null || value.Length == 0)
|
||||||
{
|
{
|
||||||
|
@ -1337,7 +1338,19 @@ namespace EonaCat.Network
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var addrs = System.Net.Dns.GetHostAddresses(value);
|
var addrs = System.Net.Dns.GetHostAddresses(value);
|
||||||
return addrs[0];
|
|
||||||
|
if (useIPv6)
|
||||||
|
{
|
||||||
|
// Find the first IPv6 address in the list, if available
|
||||||
|
var ipv6Addr = addrs.FirstOrDefault(a => a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6);
|
||||||
|
if (ipv6Addr != null)
|
||||||
|
{
|
||||||
|
return ipv6Addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If IPv6 is not requested or not available, return the first IPv4 address
|
||||||
|
return addrs.FirstOrDefault(a => a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
@ -1345,6 +1358,7 @@ namespace EonaCat.Network
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static List<TSource> ToList<TSource>(this IEnumerable<TSource> source)
|
internal static List<TSource> ToList<TSource>(this IEnumerable<TSource> source)
|
||||||
{
|
{
|
||||||
return new List<TSource>(source);
|
return new List<TSource>(source);
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace EonaCat.Network
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpServer(string url)
|
public HttpServer(string url, bool forceIpV6 = false)
|
||||||
{
|
{
|
||||||
if (url == null)
|
if (url == null)
|
||||||
{
|
{
|
||||||
|
@ -47,7 +47,7 @@ namespace EonaCat.Network
|
||||||
|
|
||||||
var host = uri.GetDnsSafeHost(true);
|
var host = uri.GetDnsSafeHost(true);
|
||||||
|
|
||||||
var addr = host.ToIPAddress();
|
var addr = host.ToIPAddress(forceIpV6);
|
||||||
if (addr == null)
|
if (addr == null)
|
||||||
{
|
{
|
||||||
message = "The host part could not be converted to an IP address.";
|
message = "The host part could not be converted to an IP address.";
|
||||||
|
|
|
@ -37,7 +37,7 @@ namespace EonaCat.Network
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public WSServer(string url)
|
public WSServer(string url, bool forceIpV6 = false)
|
||||||
{
|
{
|
||||||
if (url == null)
|
if (url == null)
|
||||||
{
|
{
|
||||||
|
@ -56,7 +56,7 @@ namespace EonaCat.Network
|
||||||
|
|
||||||
var host = uri.DnsSafeHost;
|
var host = uri.DnsSafeHost;
|
||||||
|
|
||||||
var addr = host.ToIPAddress();
|
var addr = host.ToIPAddress(forceIpV6);
|
||||||
if (addr == null)
|
if (addr == null)
|
||||||
{
|
{
|
||||||
message = "The host part could not be converted to an IP address.";
|
message = "The host part could not be converted to an IP address.";
|
||||||
|
|
Loading…
Reference in New Issue