3 using System.Net.Sockets;
5 using System.Threading.Tasks;
6 using System.Security.Permissions;
7 using System.Diagnostics.CodeAnalysis;
10 namespace System.Net.NetworkInformation
13 public abstract class IPGlobalProperties
15 public static IPGlobalProperties GetIPGlobalProperties()
18 return new AndroidIPGlobalProperties ();
19 #elif MONOTOUCH || XAMMAC || MOBILE_STATIC
20 return new UnixIPGlobalProperties ();
22 switch (Environment.OSVersion.Platform) {
24 MibIPGlobalProperties impl = null;
25 if (Directory.Exists (MibIPGlobalProperties.ProcDir)) {
26 impl = new MibIPGlobalProperties (MibIPGlobalProperties.ProcDir);
27 if (File.Exists (impl.StatisticsFile))
30 if (Directory.Exists (MibIPGlobalProperties.CompatProcDir)) {
31 impl = new MibIPGlobalProperties (MibIPGlobalProperties.CompatProcDir);
32 if (File.Exists (impl.StatisticsFile))
35 return new UnixIPGlobalProperties ();
37 return new Win32IPGlobalProperties ();
40 (new NetworkInformationPermission(NetworkInformationAccess.Read)).Demand();
41 return new SystemIPGlobalProperties();
45 internal static IPGlobalProperties InternalGetIPGlobalProperties()
48 return GetIPGlobalProperties();
50 return new SystemIPGlobalProperties();
54 /// Gets the Active Udp Listeners on this machine
55 public abstract IPEndPoint[] GetActiveUdpListeners();
57 /// Gets the Active Tcp Listeners on this machine
58 public abstract IPEndPoint[] GetActiveTcpListeners ();
60 /// Gets the Active Udp Listeners on this machine
61 public abstract TcpConnectionInformation[] GetActiveTcpConnections();
63 /// Gets the Dynamic Host Configuration Protocol (DHCP) scope name.
64 public abstract string DhcpScopeName {get;}
66 /// Gets the domain in which the local computer is registered.
68 public abstract string DomainName {get;}
70 /// Gets the host name for the local computer.
72 public abstract string HostName {get;}
74 /// Gets a bool value that specifies whether the local computer is acting as a Windows Internet Name Service (WINS) proxy.
75 public abstract bool IsWinsProxy {get;}
77 /// Gets the Network Basic Input/Output System (NetBIOS) node type of the local computer.
78 public abstract NetBiosNodeType NodeType{get;}
81 public abstract TcpStatistics GetTcpIPv4Statistics();
83 public abstract TcpStatistics GetTcpIPv6Statistics();
85 /// Provides Internet Control Message Protocol (ICMP) version 4 statistical data for the local computer.
86 /// Provides User Datagram Protocol (UDP) statistical data for the local computer.
88 public abstract UdpStatistics GetUdpIPv4Statistics();
89 public abstract UdpStatistics GetUdpIPv6Statistics();
91 /// Provides Internet Control Message Protocol (ICMP) version 4 statistical data for the local computer.
93 public abstract IcmpV4Statistics GetIcmpV4Statistics();
95 /// Provides Internet Control Message Protocol (ICMP) version 6 statistical data for the local computer.
97 public abstract IcmpV6Statistics GetIcmpV6Statistics();
99 /// Provides Internet Protocol (IP) statistical data for the local computer.
100 public abstract IPGlobalStatistics GetIPv4GlobalStatistics();
101 public abstract IPGlobalStatistics GetIPv6GlobalStatistics();
103 /// Returns a list of all unicast IP addresses after ensuring they are all stable
104 public virtual UnicastIPAddressInformationCollection GetUnicastAddresses()
106 throw ExceptionHelper.MethodNotImplementedException;
109 public virtual IAsyncResult BeginGetUnicastAddresses(AsyncCallback callback, object state)
111 throw ExceptionHelper.MethodNotImplementedException;
114 public virtual UnicastIPAddressInformationCollection EndGetUnicastAddresses(IAsyncResult asyncResult)
116 throw ExceptionHelper.MethodNotImplementedException;
119 //************* Task-based async public methods *************************
120 [HostProtection(ExternalThreading = true)]
121 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Unicast")]
122 public virtual Task<UnicastIPAddressInformationCollection> GetUnicastAddressesAsync()
124 return Task<UnicastIPAddressInformationCollection>.Factory.FromAsync(BeginGetUnicastAddresses, EndGetUnicastAddresses, null);