Fix GetIp

This commit is contained in:
Mootfrost777 2024-08-23 22:45:53 +03:00
parent 9cd3930731
commit bd73824cb4
6 changed files with 136 additions and 185 deletions

View file

@ -44,6 +44,9 @@
#begin MapData/TileMaps/main.tmj #begin MapData/TileMaps/main.tmj
/copy:MapData/TileMaps/main.tmj /copy:MapData/TileMaps/main.tmj
#begin MapData/TileSets/bonfire.tsj
/copy:MapData/TileSets/bonfire.tsj
#begin MapData/TileSets/IconSet.tsj #begin MapData/TileSets/IconSet.tsj
/copy:MapData/TileSets/IconSet.tsj /copy:MapData/TileSets/IconSet.tsj
@ -92,30 +95,12 @@
/processorParam:Quality=Best /processorParam:Quality=Best
/build:sounds/Loot.wav /build:sounds/Loot.wav
#begin sounds/Loot.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/Loot.wav
#begin sounds/Odevanie odezdi.wav #begin sounds/Odevanie odezdi.wav
/importer:WavImporter /importer:WavImporter
/processor:SoundEffectProcessor /processor:SoundEffectProcessor
/processorParam:Quality=Best /processorParam:Quality=Best
/build:sounds/Odevanie odezdi.wav /build:sounds/Odevanie odezdi.wav
#begin sounds/Odevanie odezdi.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/Odevanie odezdi.wav
#begin sounds/Pieot wodichky.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/Pieot wodichky.wav
#begin sounds/Pieot wodichky.wav #begin sounds/Pieot wodichky.wav
/importer:WavImporter /importer:WavImporter
/processor:SoundEffectProcessor /processor:SoundEffectProcessor
@ -128,18 +113,6 @@
/processorParam:Quality=Best /processorParam:Quality=Best
/build:sounds/Sshetchik geigera.wav /build:sounds/Sshetchik geigera.wav
#begin sounds/Sshetchik geigera.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/Sshetchik geigera.wav
#begin sounds/Tabletki 2.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/Tabletki 2.wav
#begin sounds/Tabletki 2.wav #begin sounds/Tabletki 2.wav
/importer:WavImporter /importer:WavImporter
/processor:SoundEffectProcessor /processor:SoundEffectProcessor
@ -152,18 +125,6 @@
/processorParam:Quality=Best /processorParam:Quality=Best
/build:sounds/Zombi napal.wav /build:sounds/Zombi napal.wav
#begin sounds/Zombi napal.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/Zombi napal.wav
#begin sounds/Zombi stoit.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/Zombi stoit.wav
#begin sounds/Zombi stoit.wav #begin sounds/Zombi stoit.wav
/importer:WavImporter /importer:WavImporter
/processor:SoundEffectProcessor /processor:SoundEffectProcessor
@ -182,14 +143,8 @@
/processorParam:Quality=Best /processorParam:Quality=Best
/build:sounds/zombie sound.wav /build:sounds/zombie sound.wav
#begin Textures/Animations/player_down_idle.animation #begin Textures/Animations/explosion_1.animation
/copy:Textures/Animations/player_down_idle.animation /copy:Textures/Animations/explosion_1.animation
#begin Textures/Animations/player_down-left_idle.animation
/copy:Textures/Animations/player_down-left_idle.animation
#begin Textures/Animations/player_down-right_idle.animation
/copy:Textures/Animations/player_down-right_idle.animation
#begin Textures/Animations/player_idle_down_mining.animation #begin Textures/Animations/player_idle_down_mining.animation
/copy:Textures/Animations/player_idle_down_mining.animation /copy:Textures/Animations/player_idle_down_mining.animation
@ -215,77 +170,65 @@
#begin Textures/Animations/player_idle_top-rights_mining.animation #begin Textures/Animations/player_idle_top-rights_mining.animation
/copy:Textures/Animations/player_idle_top-rights_mining.animation /copy:Textures/Animations/player_idle_top-rights_mining.animation
#begin Textures/Animations/player_left_idle.animation #begin Textures/Animations/player_look_down_weapon.animation
/copy:Textures/Animations/player_left_idle.animation /copy:Textures/Animations/player_look_down_weapon.animation
#begin Textures/Animations/player_look_down.animation #begin Textures/Animations/player_look_down.animation
/copy:Textures/Animations/player_look_down.animation /copy:Textures/Animations/player_look_down.animation
#begin Textures/Animations/player_look_down_weapon.animation #begin Textures/Animations/player_look_left_down_weapon.animation
/copy:Textures/Animations/player_look_down_weapon.animation /copy:Textures/Animations/player_look_left_down_weapon.animation
#begin Textures/Animations/player_look_left.animation
/copy:Textures/Animations/player_look_left.animation
#begin Textures/Animations/player_look_left_down.animation #begin Textures/Animations/player_look_left_down.animation
/copy:Textures/Animations/player_look_left_down.animation /copy:Textures/Animations/player_look_left_down.animation
#begin Textures/Animations/player_look_left_down_weapon.animation #begin Textures/Animations/player_look_left_up_weapon.animation
/copy:Textures/Animations/player_look_left_down_weapon.animation /copy:Textures/Animations/player_look_left_up_weapon.animation
#begin Textures/Animations/player_look_left_up.animation #begin Textures/Animations/player_look_left_up.animation
/copy:Textures/Animations/player_look_left_up.animation /copy:Textures/Animations/player_look_left_up.animation
#begin Textures/Animations/player_look_left_up_weapon.animation
/copy:Textures/Animations/player_look_left_up_weapon.animation
#begin Textures/Animations/player_look_left_weapon.animation #begin Textures/Animations/player_look_left_weapon.animation
/copy:Textures/Animations/player_look_left_weapon.animation /copy:Textures/Animations/player_look_left_weapon.animation
#begin Textures/Animations/player_look_right.animation #begin Textures/Animations/player_look_left.animation
/copy:Textures/Animations/player_look_right.animation /copy:Textures/Animations/player_look_left.animation
#begin Textures/Animations/player_look_right_down.animation
/copy:Textures/Animations/player_look_right_down.animation
#begin Textures/Animations/player_look_right_down_weapon.animation #begin Textures/Animations/player_look_right_down_weapon.animation
/copy:Textures/Animations/player_look_right_down_weapon.animation /copy:Textures/Animations/player_look_right_down_weapon.animation
#begin Textures/Animations/player_look_right_up.animation #begin Textures/Animations/player_look_right_down.animation
/copy:Textures/Animations/player_look_right_up.animation /copy:Textures/Animations/player_look_right_down.animation
#begin Textures/Animations/player_look_right_up_weapon.animation #begin Textures/Animations/player_look_right_up_weapon.animation
/copy:Textures/Animations/player_look_right_up_weapon.animation /copy:Textures/Animations/player_look_right_up_weapon.animation
#begin Textures/Animations/player_look_right_up.animation
/copy:Textures/Animations/player_look_right_up.animation
#begin Textures/Animations/player_look_right_weapon.animation #begin Textures/Animations/player_look_right_weapon.animation
/copy:Textures/Animations/player_look_right_weapon.animation /copy:Textures/Animations/player_look_right_weapon.animation
#begin Textures/Animations/player_look_up.animation #begin Textures/Animations/player_look_right.animation
/copy:Textures/Animations/player_look_up.animation /copy:Textures/Animations/player_look_right.animation
#begin Textures/Animations/player_look_up_weapon.animation #begin Textures/Animations/player_look_up_weapon.animation
/copy:Textures/Animations/player_look_up_weapon.animation /copy:Textures/Animations/player_look_up_weapon.animation
#begin Textures/Animations/player_right_idle.animation #begin Textures/Animations/player_look_up.animation
/copy:Textures/Animations/player_right_idle.animation /copy:Textures/Animations/player_look_up.animation
#begin Textures/Animations/player_run_down.animation #begin Textures/Animations/player_run_down.animation
/copy:Textures/Animations/player_run_down.animation /copy:Textures/Animations/player_run_down.animation
#begin Textures/Animations/player_run_left.animation
/copy:Textures/Animations/player_run_left.animation
#begin Textures/Animations/player_run_left_down.animation #begin Textures/Animations/player_run_left_down.animation
/copy:Textures/Animations/player_run_left_down.animation /copy:Textures/Animations/player_run_left_down.animation
#begin Textures/Animations/player_run_left_up.animation #begin Textures/Animations/player_run_left_up.animation
/copy:Textures/Animations/player_run_left_up.animation /copy:Textures/Animations/player_run_left_up.animation
#begin Textures/Animations/player_run_right.animation #begin Textures/Animations/player_run_left.animation
/copy:Textures/Animations/player_run_right.animation /copy:Textures/Animations/player_run_left.animation
#begin Textures/Animations/player_run_right.zip
/copy:Textures/Animations/player_run_right.zip
#begin Textures/Animations/player_run_right_down.animation #begin Textures/Animations/player_run_right_down.animation
/copy:Textures/Animations/player_run_right_down.animation /copy:Textures/Animations/player_run_right_down.animation
@ -293,6 +236,12 @@
#begin Textures/Animations/player_run_right_up.animation #begin Textures/Animations/player_run_right_up.animation
/copy:Textures/Animations/player_run_right_up.animation /copy:Textures/Animations/player_run_right_up.animation
#begin Textures/Animations/player_run_right.animation
/copy:Textures/Animations/player_run_right.animation
#begin Textures/Animations/player_run_right.zip
/copy:Textures/Animations/player_run_right.zip
#begin Textures/Animations/player_run_up.animation #begin Textures/Animations/player_run_up.animation
/copy:Textures/Animations/player_run_up.animation /copy:Textures/Animations/player_run_up.animation
@ -302,15 +251,30 @@
#begin Textures/Animations/player_top_mining.animation #begin Textures/Animations/player_top_mining.animation
/copy:Textures/Animations/player_top_mining.animation /copy:Textures/Animations/player_top_mining.animation
#begin Textures/Animations/player_top-left_idle.animation
/copy:Textures/Animations/player_top-left_idle.animation
#begin Textures/Animations/player_top-right_idle.animation
/copy:Textures/Animations/player_top-right_idle.animation
#begin Textures/Animations/running_top.animation #begin Textures/Animations/running_top.animation
/copy:Textures/Animations/running_top.animation /copy:Textures/Animations/running_top.animation
#begin Textures/Animations/Simple Idles/player_down_idle.animation
/copy:Textures/Animations/Simple Idles/player_down_idle.animation
#begin Textures/Animations/Simple Idles/player_down-left_idle.animation
/copy:Textures/Animations/Simple Idles/player_down-left_idle.animation
#begin Textures/Animations/Simple Idles/player_down-right_idle.animation
/copy:Textures/Animations/Simple Idles/player_down-right_idle.animation
#begin Textures/Animations/Simple Idles/player_left_idle.animation
/copy:Textures/Animations/Simple Idles/player_left_idle.animation
#begin Textures/Animations/Simple Idles/player_right_idle.animation
/copy:Textures/Animations/Simple Idles/player_right_idle.animation
#begin Textures/Animations/Simple Idles/player_top-left_idle.animation
/copy:Textures/Animations/Simple Idles/player_top-left_idle.animation
#begin Textures/Animations/Simple Idles/player_top-right_idle.animation
/copy:Textures/Animations/Simple Idles/player_top-right_idle.animation
#begin Textures/Animations/testAnimation.animation #begin Textures/Animations/testAnimation.animation
/copy:Textures/Animations/testAnimation.animation /copy:Textures/Animations/testAnimation.animation
@ -332,18 +296,6 @@
#begin Textures/Animations/zombie_walk.animation #begin Textures/Animations/zombie_walk.animation
/copy:Textures/Animations/zombie_walk.animation /copy:Textures/Animations/zombie_walk.animation
#begin Textures/AnimationTextures/Character/hr-level1_idle.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/AnimationTextures/Character/hr-level1_idle.png
#begin Textures/AnimationTextures/Character/hr-level1_idle_gun.png #begin Textures/AnimationTextures/Character/hr-level1_idle_gun.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -356,6 +308,18 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/AnimationTextures/Character/hr-level1_idle_gun.png /build:Textures/AnimationTextures/Character/hr-level1_idle_gun.png
#begin Textures/AnimationTextures/Character/hr-level1_idle.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/AnimationTextures/Character/hr-level1_idle.png
#begin Textures/AnimationTextures/Character/hr-level1_mining_tool-1.png #begin Textures/AnimationTextures/Character/hr-level1_mining_tool-1.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -380,18 +344,6 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/AnimationTextures/Character/hr-level1_mining_tool-2.png /build:Textures/AnimationTextures/Character/hr-level1_mining_tool-2.png
#begin Textures/AnimationTextures/Character/hr-level1_running.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/AnimationTextures/Character/hr-level1_running.png
#begin Textures/AnimationTextures/Character/hr-level1_running_gun.png #begin Textures/AnimationTextures/Character/hr-level1_running_gun.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -404,6 +356,18 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/AnimationTextures/Character/hr-level1_running_gun.png /build:Textures/AnimationTextures/Character/hr-level1_running_gun.png
#begin Textures/AnimationTextures/Character/hr-level1_running.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/AnimationTextures/Character/hr-level1_running.png
#begin Textures/AnimationTextures/unicorn.png #begin Textures/AnimationTextures/unicorn.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -440,7 +404,6 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/AnimationTextures/Zombie/zombie_spritesheet_v2.png /build:Textures/AnimationTextures/Zombie/zombie_spritesheet_v2.png
#begin Textures/Effects/explosion.png #begin Textures/Effects/explosion.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -585,18 +548,6 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/GUI/ButtonI.png /build:Textures/GUI/ButtonI.png
#begin Textures/GUI/checkboxs_off.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/GUI/checkboxs_off.png
#begin Textures/GUI/checkboxs_off-on.png #begin Textures/GUI/checkboxs_off-on.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -609,6 +560,18 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/GUI/checkboxs_off-on.png /build:Textures/GUI/checkboxs_off-on.png
#begin Textures/GUI/checkboxs_off.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/GUI/checkboxs_off.png
#begin Textures/GUI/checkboxs_on.png #begin Textures/GUI/checkboxs_on.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -645,18 +608,6 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/GUI/mouse.png /build:Textures/GUI/mouse.png
#begin Textures/GUI/switch.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/GUI/switch.png
#begin Textures/GUI/Switch_backgrownd.png #begin Textures/GUI/Switch_backgrownd.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -669,6 +620,18 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/GUI/Switch_backgrownd.png /build:Textures/GUI/Switch_backgrownd.png
#begin Textures/GUI/switch.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/GUI/switch.png
#begin Textures/icons/12.png #begin Textures/icons/12.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -885,18 +848,6 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/icons/ExitZone.png /build:Textures/icons/ExitZone.png
#begin Textures/icons/ExitZone.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/icons/ExitZone.png
#begin Textures/icons/Material/Fabric.png #begin Textures/icons/Material/Fabric.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor

View file

@ -31,7 +31,7 @@ public class DebugHUD
public void Draw(SpriteBatch spriteBatch) public void Draw(SpriteBatch spriteBatch)
{ {
return;//TODO delete //return;//TODO delete
var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList()); var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList());
spriteBatch.Begin(); spriteBatch.Begin();
spriteBatch.DrawString( spriteBatch.DrawString(

View file

@ -28,7 +28,7 @@ public class WaitingForPlayersGUI : AbstractGUI
int width = AppManager.Instance.CurentScreenResolution.X; int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y; int height = AppManager.Instance.CurentScreenResolution.Y;
menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures/GUI/background/Waiting" }; menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures/GUI/background/waiting" };
Elements.Add(menuBackground); Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content); menuBackground.LoadTexture(AppManager.Instance.Content);
// string pcIp = // string pcIp =

View file

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Data.SqlTypes; using System.Data.SqlTypes;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets; using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
@ -242,19 +243,18 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
#endregion #endregion
public static IPAddress GetIp() public static IPAddress GetIp()
{ {
string hostName = Dns.GetHostName(); // Retrive the Name of HOST var ips = NetworkInterface.GetAllNetworkInterfaces()
var ipList = Dns.GetHostEntry(hostName).AddressList; .Where(x => x.OperationalStatus == OperationalStatus.Up)
var ipV4List = new List<IPAddress>(); .Where(x => x.NetworkInterfaceType is NetworkInterfaceType.Wireless80211
foreach (var ip in ipList) or NetworkInterfaceType.Ethernet)
.SelectMany(x => x.GetIPProperties().UnicastAddresses)
.Where(x => x.Address.AddressFamily == AddressFamily.InterNetwork)
.Select(x => x.Address)
.ToList();
if (ips.Count > 0)
{ {
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) return ips[^1];
{
ipV4List.Add(ip);
}
}
if (ipV4List.Count>0)
{
return ipV4List[ipV4List.Count - 1];
} }
return IPAddress.Loopback; return IPAddress.Loopback;
} }

View file

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Net.NetworkInformation;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
@ -66,20 +67,18 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
/// <returns></returns> /// <returns></returns>
public static IPAddress GetIp() public static IPAddress GetIp()
{ {
string hostName = Dns.GetHostName(); // Retrive the Name of HOST var ips = NetworkInterface.GetAllNetworkInterfaces()
var ipList = Dns.GetHostEntry(hostName).AddressList; .Where(x => x.OperationalStatus == OperationalStatus.Up)
.Where(x => x.NetworkInterfaceType is NetworkInterfaceType.Wireless80211
or NetworkInterfaceType.Ethernet)
.SelectMany(x => x.GetIPProperties().UnicastAddresses)
.Where(x => x.Address.AddressFamily == AddressFamily.InterNetwork)
.Select(x => x.Address)
.ToList();
var ipV4List = new List<IPAddress>(); if (ips.Count > 0)
foreach (var ip in ipList)
{ {
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) return ips[^1];
{
ipV4List.Add(ip);
}
}
if (ipV4List.Count > 0)
{
return ipV4List[ipV4List.Count - 1];
} }
return IPAddress.Loopback; return IPAddress.Loopback;
} }

View file

@ -29,6 +29,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303" /> <PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303" />
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.303" /> <PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.303" />
<PackageReference Include="MonoGame.Templates.CSharp" Version="3.8.1.1-kniEngine" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>