123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System;
- using System.Collections.Generic;
- using System.Net;
- using System.Net.Sockets;
- using System.Net.NetworkInformation;
- using Utilities;
- namespace SMBServer
- {
- public class NetworkInterfaceHelper
- {
- public static List<IPAddress> GetHostIPAddresses()
- {
- List<IPAddress> result = new List<IPAddress>();
- foreach (NetworkInterface netInterface in NetworkInterface.GetAllNetworkInterfaces())
- {
- IPInterfaceProperties ipProperties = netInterface.GetIPProperties();
- foreach (UnicastIPAddressInformation addressInfo in ipProperties.UnicastAddresses)
- {
- if (addressInfo.Address.AddressFamily == AddressFamily.InterNetwork)
- {
- result.Add(addressInfo.Address);
- }
- }
- }
- return result;
- }
- public static IPAddress GetSubnetMask(IPAddress ipAddress)
- {
- foreach (NetworkInterface netInterface in NetworkInterface.GetAllNetworkInterfaces())
- {
- IPInterfaceProperties ipProperties = netInterface.GetIPProperties();
- foreach (UnicastIPAddressInformation addressInfo in ipProperties.UnicastAddresses)
- {
- if (addressInfo.Address.AddressFamily == AddressFamily.InterNetwork)
- {
- if (IPAddress.Equals(addressInfo.Address, ipAddress))
- {
- return addressInfo.IPv4Mask;
- }
- }
- }
- }
- return null;
- }
- }
- }
|