improve network address detection

This commit is contained in:
Luke Pulverenti 2016-12-12 16:33:37 -05:00
parent 87c9f26e65
commit 6fe933fde4
3 changed files with 47 additions and 5 deletions

View File

@ -198,6 +198,12 @@ namespace Emby.Common.Implementations.Networking
return Dns.GetHostAddressesAsync(hostName);
}
private readonly List<NetworkInterfaceType> _validNetworkInterfaceTypes = new List<NetworkInterfaceType>
{
NetworkInterfaceType.Ethernet,
NetworkInterfaceType.Wireless80211
};
private List<IPAddress> GetIPsDefault()
{
NetworkInterface[] interfaces;
@ -223,9 +229,22 @@ namespace Emby.Common.Implementations.Networking
{
Logger.Debug("Querying interface: {0}. Type: {1}. Status: {2}", network.Name, network.NetworkInterfaceType, network.OperationalStatus);
var properties = network.GetIPProperties();
var ipProperties = network.GetIPProperties();
return properties.UnicastAddresses
// Try to exclude virtual adapters
// http://stackoverflow.com/questions/8089685/c-sharp-finding-my-machines-local-ip-address-and-not-the-vms
var addr = ipProperties.GatewayAddresses.FirstOrDefault();
if (addr == null|| string.Equals(addr.Address.ToString(), "0.0.0.0", StringComparison.OrdinalIgnoreCase))
{
return new List<IPAddress>();
}
//if (!_validNetworkInterfaceTypes.Contains(network.NetworkInterfaceType))
//{
// return new List<IPAddress>();
//}
return ipProperties.UnicastAddresses
.Where(i => i.IsDnsEligible)
.Select(i => i.Address)
.Where(i => i.AddressFamily == AddressFamily.InterNetwork)

View File

@ -37,5 +37,10 @@
<ProjectReference Include="..\..\ServiceStack\ServiceStack.csproj" />
<ProjectReference Include="..\..\SocketHttpListener.Portable\SocketHttpListener.Portable.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link>
</Compile>
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@ -1,5 +1,5 @@
{
"version": "1.0.0-*",
"version": "3.1.0-*",
"buildOptions": {
"emitEntryPoint": true
},
@ -33,8 +33,26 @@
"win10-arm64": {},
"osx.10.10-x64": {},
"osx.10.11-x64": {},
"osx.10.12-x64": {},
"ubuntu.14.04-x64": {}
"osx.10.12-x64": ,
"rhel.7.0-x64": {},
"rhel.7.1-x64": {},
"rhel.7.2-x64": {},
"ubuntu.14.04-x64": {},
"ubuntu.14.10-x64": {},
"ubuntu.15.04-x64": {},
"ubuntu.15.10-x64": {},
"ubuntu.16.04-x64": {},
"ubuntu.16.10-x64": {},
"centos.7-x64": {},
"debian.8-x64": {},
"fedora.23-x64": {},
"fedora.24-x64": {},
"opensuse.13.2-x64": {},
"opensuse.42.1-x64": {},
"ol.7-x64": {},
"ol.7.0-x64": {},
"ol.7.1-x64": {},
"ol.7.2-x64": {}
},
"frameworks": {