diff options
| author | Roy <Roy.mail.net@gmail.com> | 2023-01-31 09:51:01 +0200 |
|---|---|---|
| committer | Roy <Roy.mail.net@gmail.com> | 2023-01-31 09:51:01 +0200 |
| commit | 2b9a91ba032dcbbeedaefb1d7b06cb93285b99df (patch) | |
| tree | b3895a89b3f3b73009b260ad2b062e8547878f09 /Software/Visual_Studio/Tango.Transport/Helpers/IPAddressHelper.cs | |
| parent | 180ba6c91451ace9f20bbad8ab4a64c9f25ab83c (diff) | |
| parent | 1c913a54575b885cb63acd4b6362e7b5669f856c (diff) | |
| download | Tango-2b9a91ba032dcbbeedaefb1d7b06cb93285b99df.tar.gz Tango-2b9a91ba032dcbbeedaefb1d7b06cb93285b99df.zip | |
Merged I4.0
Diffstat (limited to 'Software/Visual_Studio/Tango.Transport/Helpers/IPAddressHelper.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Transport/Helpers/IPAddressHelper.cs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Transport/Helpers/IPAddressHelper.cs b/Software/Visual_Studio/Tango.Transport/Helpers/IPAddressHelper.cs new file mode 100644 index 000000000..04a15caa3 --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Helpers/IPAddressHelper.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Net.Sockets; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Transport.Helpers +{ + public static class IPAddressHelper + { + public static string GetLocalIpAddress() + { + foreach (var netI in NetworkInterface.GetAllNetworkInterfaces()) + { + if (netI.NetworkInterfaceType != NetworkInterfaceType.Wireless80211 && + (netI.NetworkInterfaceType != NetworkInterfaceType.Ethernet || + netI.OperationalStatus != OperationalStatus.Up)) continue; + foreach (var uniIpAddrInfo in netI.GetIPProperties().UnicastAddresses.Where(x => netI.GetIPProperties().GatewayAddresses.Count > 0)) + { + + if (uniIpAddrInfo.Address.AddressFamily == AddressFamily.InterNetwork && + uniIpAddrInfo.AddressPreferredLifetime != uint.MaxValue) + return uniIpAddrInfo.Address.ToString(); + } + } + return null; + } + } +} |
