-
Notifications
You must be signed in to change notification settings - Fork 803
Expand file tree
/
Copy pathNetworkInterface.cs
More file actions
552 lines (479 loc) · 26.2 KB
/
NetworkInterface.cs
File metadata and controls
552 lines (479 loc) · 26.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Threading.Tasks;
using Microsoft.Win32;
using NETworkManager.Utilities;
namespace NETworkManager.Models.Network;
/// <summary>
/// Provides static and instance methods for retrieving information about network interfaces, detecting local IP
/// addresses and gateways, and configuring network interface settings on the local machine.
/// </summary>
/// <remarks>The NetworkInterface class offers both synchronous and asynchronous methods for enumerating network
/// interfaces, detecting routing and gateway information, and performing network configuration tasks such as setting IP
/// addresses, DNS servers, and flushing the DNS cache. Most configuration operations require administrative privileges.
/// Events are provided to notify when user-initiated cancellations occur, such as when a UAC prompt is dismissed. This
/// class is intended for use in applications that need to query or modify network interface settings
/// programmatically.</remarks>
public sealed class NetworkInterface
{
#region Variables
/// <summary>
/// List of network interface name patterns to filter out virtual/filter adapters
/// introduced in .NET 9/10. These are typically not actual network interfaces but rather
/// drivers, filters, or extensions attached to real network interfaces.
/// See: https://github.com/dotnet/runtime/issues/122751
/// </summary>
private static readonly List<string> NetworkInterfaceFilteredPatterns =
[
"Hyper-V Virtual Switch Extension Filter",
"Hyper-V Virtual Switch Extension Adapter",
"WFP Native MAC Layer LightWeight Filter",
"Npcap Packet Driver (NPCAP)",
"QoS Packet Scheduler",
"WFP 802.3 MAC Layer LightWeight Filter",
"Ethernet (Kerneldebugger)",
"Filter Driver",
"WAN Miniport",
"Microsoft Wi-Fi Direct Virtual Adapter"
];
#endregion
#region Methods
/// <summary>
/// Asynchronously retrieves a list of available network interfaces on the local machine.
/// </summary>
/// <returns>A task that represents the asynchronous operation. The task result contains a list of <see
/// cref="NetworkInterfaceInfo"/> objects describing each detected network interface.</returns>
public static Task<List<NetworkInterfaceInfo>> GetNetworkInterfacesAsync()
{
return Task.Run(GetNetworkInterfaces);
}
/// <summary>
/// Retrieves a list of network interfaces on the local machine, including detailed information about each interface
/// such as addresses, gateways, and DHCP settings.
/// </summary>
/// <remarks>Only Ethernet, Wireless80211, and proprietary virtual/internal interfaces are included. The
/// returned information includes both IPv4 and IPv6 details, as well as DHCP and DNS configuration where available.
/// This method may require appropriate permissions to access network configuration data.</remarks>
/// <returns>A list of <see cref="NetworkInterfaceInfo"/> objects, each representing a network interface with its associated
/// properties. The list is empty if no matching interfaces are found.</returns>
public static List<NetworkInterfaceInfo> GetNetworkInterfaces()
{
List<NetworkInterfaceInfo> listNetworkInterfaceInfo = [];
foreach (var networkInterface in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
{
// NetworkInterfaceType 53 is proprietary virtual/internal interface
// https://docs.microsoft.com/en-us/windows-hardware/drivers/network/ndis-interface-types
if (networkInterface.NetworkInterfaceType != NetworkInterfaceType.Ethernet &&
networkInterface.NetworkInterfaceType != NetworkInterfaceType.Wireless80211 &&
(int)networkInterface.NetworkInterfaceType != 53)
continue;
// Filter out virtual/filter adapters introduced in .NET 9/10
// Check if the adapter name or description contains any filtered pattern
// See: https://github.com/dotnet/runtime/issues/122751
if (NetworkInterfaceFilteredPatterns.Any(pattern =>
networkInterface.Name.Contains(pattern) ||
networkInterface.Description.Contains(pattern)))
continue;
var listIPv4Address = new List<Tuple<IPAddress, IPAddress>>();
var listIPv6AddressLinkLocal = new List<IPAddress>();
var listIPv6Address = new List<IPAddress>();
var dhcpLeaseObtained = new DateTime();
var dhcpLeaseExpires = new DateTime();
var ipProperties = networkInterface.GetIPProperties();
foreach (var unicastIPAddrInfo in ipProperties.UnicastAddresses)
{
switch (unicastIPAddrInfo.Address.AddressFamily)
{
case AddressFamily.InterNetwork:
listIPv4Address.Add(new Tuple<IPAddress, IPAddress>(unicastIPAddrInfo.Address,
unicastIPAddrInfo.IPv4Mask));
dhcpLeaseExpires =
(DateTime.UtcNow + TimeSpan.FromSeconds(unicastIPAddrInfo.AddressPreferredLifetime))
.ToLocalTime();
dhcpLeaseObtained =
(DateTime.UtcNow + TimeSpan.FromSeconds(unicastIPAddrInfo.AddressValidLifetime) -
TimeSpan.FromSeconds(unicastIPAddrInfo.DhcpLeaseLifetime)).ToLocalTime();
break;
case AddressFamily.InterNetworkV6 when unicastIPAddrInfo.Address.IsIPv6LinkLocal:
listIPv6AddressLinkLocal.Add(unicastIPAddrInfo.Address);
break;
case AddressFamily.InterNetworkV6:
listIPv6Address.Add(unicastIPAddrInfo.Address);
break;
}
}
var listIPv4Gateway = new List<IPAddress>();
var listIPv6Gateway = new List<IPAddress>();
foreach (var gatewayIPAddrInfo in ipProperties.GatewayAddresses)
{
switch (gatewayIPAddrInfo.Address.AddressFamily)
{
case AddressFamily.InterNetwork:
listIPv4Gateway.Add(gatewayIPAddrInfo.Address);
break;
case AddressFamily.InterNetworkV6:
listIPv6Gateway.Add(gatewayIPAddrInfo.Address);
break;
}
}
// Check if autoconfiguration for DNS is enabled (only possible via registry key)
var nameServerKey =
Registry.LocalMachine.OpenSubKey(
$@"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{networkInterface.Id}");
var dnsAutoconfigurationEnabled = nameServerKey?.GetValue("NameServer") != null &&
string.IsNullOrEmpty(nameServerKey.GetValue("NameServer")?.ToString());
// Check if IPv4 protocol is available
var ipv4ProtocolAvailable = true;
IPv4InterfaceProperties ipv4Properties = null;
try
{
ipv4Properties = ipProperties.GetIPv4Properties();
}
catch (NetworkInformationException)
{
ipv4ProtocolAvailable = false;
}
// Check if IPv6 protocol is available
var ipv6ProtocolAvailable = true;
try
{
ipProperties.GetIPv6Properties();
}
catch (NetworkInformationException)
{
ipv6ProtocolAvailable = false;
}
listNetworkInterfaceInfo.Add(new NetworkInterfaceInfo
{
Id = networkInterface.Id,
Name = networkInterface.Name,
Description = networkInterface.Description,
Type = networkInterface.NetworkInterfaceType.ToString(),
PhysicalAddress = networkInterface.GetPhysicalAddress(),
Status = networkInterface.OperationalStatus,
IsOperational = networkInterface.OperationalStatus == OperationalStatus.Up,
Speed = networkInterface.Speed,
IPv4ProtocolAvailable = ipv4ProtocolAvailable,
IPv4Address = [.. listIPv4Address],
IPv4Gateway = [.. listIPv4Gateway],
DhcpEnabled = ipv4Properties is { IsDhcpEnabled: true },
DhcpServer = [.. ipProperties.DhcpServerAddresses.Where(dhcpServerIPAddress =>
dhcpServerIPAddress.AddressFamily == AddressFamily.InterNetwork)],
DhcpLeaseObtained = dhcpLeaseObtained,
DhcpLeaseExpires = dhcpLeaseExpires,
IPv6ProtocolAvailable = ipv6ProtocolAvailable,
IPv6AddressLinkLocal = [.. listIPv6AddressLinkLocal],
IPv6Address = [.. listIPv6Address],
IPv6Gateway = [.. listIPv6Gateway],
DNSAutoconfigurationEnabled = dnsAutoconfigurationEnabled,
DNSSuffix = ipProperties.DnsSuffix,
DNSServer = [.. ipProperties.DnsAddresses]
});
}
return listNetworkInterfaceInfo;
}
/// <summary>
/// Asynchronously determines the local IP address that would be used to route traffic to the specified remote IP
/// address.
/// </summary>
/// <remarks>This method is useful for identifying the local network interface that would be selected by
/// the system's routing table when communicating with a given remote address. The result may vary depending on the
/// current network configuration and routing rules.</remarks>
/// <param name="remoteIPAddress">The destination IP address for which to determine the corresponding local source IP address. Cannot be null.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the local IP address that would be
/// used to reach the specified remote IP address.</returns>
public static Task<IPAddress> DetectLocalIPAddressBasedOnRoutingAsync(IPAddress remoteIPAddress)
{
return Task.Run(() => DetectLocalIPAddressFromRouting(remoteIPAddress));
}
/// <summary>
/// Determines the local IP address that would be used to route traffic to the specified remote IP address.
/// </summary>
/// <remarks>This method creates a UDP socket to determine the local IP address selected by the system's
/// routing table for the given remote address. No data is sent over the network. This method may return null if the
/// routing information is unavailable or an error occurs.</remarks>
/// <param name="remoteIPAddress">The destination IP address for which to determine the local routing address. Must not be null.</param>
/// <returns>An IPAddress representing the local address that would be used to reach the specified remote address; or null if
/// the local address cannot be determined.</returns>
private static IPAddress DetectLocalIPAddressFromRouting(IPAddress remoteIPAddress)
{
var isIPv4 = remoteIPAddress.AddressFamily == AddressFamily.InterNetwork;
using var socket = new Socket(remoteIPAddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
// return null on error...
try
{
socket.Bind(new IPEndPoint(isIPv4 ? IPAddress.Any : IPAddress.IPv6Any, 0));
socket.Connect(new IPEndPoint(remoteIPAddress, 0));
if (socket.LocalEndPoint is IPEndPoint ipAddress)
return ipAddress.Address;
}
catch (SocketException) { }
return null;
}
/// <summary>
/// Asynchronously detects the local IP address associated with a network interface that matches the specified
/// address family.
/// </summary>
/// <param name="addressFamily">The address family to use when searching for a local IP address. Typically, use AddressFamily.InterNetwork for
/// IPv4 or AddressFamily.InterNetworkV6 for IPv6.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the detected local IP address, or
/// null if no suitable address is found.</returns>
public static Task<IPAddress> DetectLocalIPAddressFromNetworkInterfaceAsync(AddressFamily addressFamily)
{
return Task.Run(() => DetectLocalIPAddressFromNetworkInterface(addressFamily));
}
/// <summary>
/// Detects and returns the first local IP address assigned to an operational network interface that matches the
/// specified address family.
/// </summary>
/// <remarks>For IPv4, the method prefers non-link-local addresses but will return a link-local address if
/// no other is available. For IPv6, the method returns the first global or unique local address if present;
/// otherwise, it returns a link-local address if available. The returned address is selected from operational
/// network interfaces only.</remarks>
/// <param name="addressFamily">The address family to search for. Specify <see cref="AddressFamily.InterNetwork"/> for IPv4 addresses or <see
/// cref="AddressFamily.InterNetworkV6"/> for IPv6 addresses.</param>
/// <returns>An <see cref="IPAddress"/> representing the first detected local IP address for the specified address family, or
/// <see langword="null"/> if no suitable address is found.</returns>
public static IPAddress DetectLocalIPAddressFromNetworkInterface(AddressFamily addressFamily)
{
// Filter operational network interfaces
var networkInterfaces = GetNetworkInterfaces()
.Where(x => x.IsOperational);
var candidates = new List<IPAddress>();
// IPv4
if (addressFamily == AddressFamily.InterNetwork)
{
foreach (var networkInterface in networkInterfaces)
{
foreach (var ipAddress in networkInterface.IPv4Address)
candidates.Add(ipAddress.Item1);
}
// Prefer non-link-local addresses
var nonLinkLocal = candidates.Where(x =>
{
var bytes = x.GetAddressBytes();
return !(bytes[0] == 169 && bytes[1] == 254);
});
// Return first non-link-local or first candidate if none found (might be null - no addresses at all)
return nonLinkLocal.Any() ? nonLinkLocal.First() : candidates.FirstOrDefault();
}
// IPv6
if (addressFamily == AddressFamily.InterNetworkV6)
{
// First try to get global or unique local addresses
foreach (var networkInterface in networkInterfaces)
candidates.AddRange(networkInterface.IPv6Address);
// Return first candidate if any found
if (candidates.Count != 0)
return candidates.First();
// Fallback to link-local addresses
var firstWithLinkLocal = networkInterfaces
.FirstOrDefault(ni => ni.IPv6AddressLinkLocal.Length != 0);
if (firstWithLinkLocal != null)
return firstWithLinkLocal.IPv6AddressLinkLocal.First();
}
return null;
}
/// <summary>
/// Asynchronously detects the default gateway address associated with the specified local IP address.
/// </summary>
/// <param name="localIPAddress">The local IP address for which to determine the corresponding default gateway. Cannot be null.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the IP address of the detected
/// default gateway, or null if no gateway is found.</returns>
public static Task<IPAddress> DetectGatewayFromLocalIPAddressAsync(IPAddress localIPAddress)
{
return Task.Run(() => DetectGatewayFromLocalIPAddress(localIPAddress));
}
/// <summary>
/// Attempts to determine the default gateway address associated with the specified local IP address.
/// </summary>
/// <remarks>This method searches all available network interfaces to find one that has the specified
/// local IP address assigned. If found, it returns the first associated gateway address for that interface and
/// address family. Returns null if the local IP address is not assigned to any interface or if no gateway is
/// configured.</remarks>
/// <param name="localIPAddress">The local IP address for which to detect the corresponding gateway. Must be either an IPv4 or IPv6 address.</param>
/// <returns>An IPAddress representing the default gateway for the specified local IP address, or null if no matching gateway
/// is found.</returns>
private static IPAddress DetectGatewayFromLocalIPAddress(IPAddress localIPAddress)
{
foreach (var networkInterface in GetNetworkInterfaces())
{
// IPv4
if (localIPAddress.AddressFamily == AddressFamily.InterNetwork)
{
if (networkInterface.IPv4Address.Any(x => x.Item1.Equals(localIPAddress)))
return networkInterface.IPv4Gateway.FirstOrDefault();
}
// IPv6
if (localIPAddress.AddressFamily == AddressFamily.InterNetworkV6)
{
if (networkInterface.IPv6Address.Contains(localIPAddress))
return networkInterface.IPv6Gateway.FirstOrDefault();
}
}
return null;
}
/// <summary>
/// Asynchronously applies the specified network interface configuration.
/// </summary>
/// <param name="config">The configuration settings to apply to the network interface. Cannot be null.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
public Task ConfigureNetworkInterfaceAsync(NetworkInterfaceConfig config)
{
return Task.Run(() => ConfigureNetworkInterface(config));
}
/// <summary>
/// Configures the network interface according to the specified settings.
/// </summary>
/// <remarks>This method applies the provided network configuration by executing system commands. If
/// static IP or DNS settings are enabled in the configuration, the corresponding values are set; otherwise, DHCP is
/// used. The method may prompt for elevated permissions depending on system policy.</remarks>
/// <param name="config">An object containing the configuration parameters for the network interface, including IP address, subnet mask,
/// gateway, and DNS server settings. Cannot be null.</param>
private void ConfigureNetworkInterface(NetworkInterfaceConfig config)
{
// IP
var command = $"netsh interface ipv4 set address name='{config.Name}'";
command += config.EnableStaticIPAddress
? $" source=static address={config.IPAddress} mask={config.Subnetmask} gateway={config.Gateway};"
: " source=dhcp;";
// DNS
command += $"netsh interface ipv4 set DNSservers name='{config.Name}'";
command += config.EnableStaticDNS
? $" source=static address={config.PrimaryDNSServer} register=primary validate=no;"
: " source=dhcp;";
command += config.EnableStaticDNS && !string.IsNullOrEmpty(config.SecondaryDNSServer)
? $"netsh interface ipv4 add DNSservers name='{config.Name}' address={config.SecondaryDNSServer} index=2 validate=no;"
: "";
try
{
PowerShellHelper.ExecuteCommand(command, true);
}
catch (Win32Exception win32Ex)
{
switch (win32Ex.NativeErrorCode)
{
case 1223:
OnUserHasCanceled();
break;
default:
throw;
}
}
}
/// <summary>
/// Asynchronously flushes the system DNS resolver cache.
/// </summary>
/// <remarks>This method initiates the DNS cache flush operation on a background thread. The operation may
/// require elevated permissions depending on the system configuration.</remarks>
/// <returns>A task that represents the asynchronous flush operation.</returns>
public static Task FlushDnsAsync()
{
return Task.Run(FlushDns);
}
/// <summary>
/// Clears the local DNS resolver cache on the system by executing the appropriate system command.
/// </summary>
/// <remarks>This method requires administrative privileges to successfully flush the DNS cache. If the
/// application does not have sufficient permissions, the operation may fail.</remarks>
private static void FlushDns()
{
const string command = "ipconfig /flushdns;";
PowerShellHelper.ExecuteCommand(command);
}
/// <summary>
/// Asynchronously releases and renews the IP configuration for the specified network adapter using the given mode.
/// </summary>
/// <param name="mode">The release and renew operation mode to apply to the network adapter.</param>
/// <param name="adapterName">The name of the network adapter whose IP configuration will be released and renewed. Cannot be null or empty.</param>
/// <returns>A task that represents the asynchronous release and renew operation.</returns>
public static Task ReleaseRenewAsync(IPConfigReleaseRenewMode mode, string adapterName)
{
return Task.Run(() => ReleaseRenew(mode, adapterName));
}
/// <summary>
/// Releases and/or renews the IP configuration for the specified network adapter using the given mode.
/// </summary>
/// <remarks>This method executes the appropriate 'ipconfig' commands based on the specified mode. The
/// operation affects only the adapter identified by the provided name. Ensure that the caller has sufficient
/// privileges to modify network settings.</remarks>
/// <param name="mode">A value that specifies which IP configuration operation to perform. Determines whether to release, renew, or
/// perform both actions for IPv4 and/or IPv6 addresses.</param>
/// <param name="adapterName">The name of the network adapter to target for the release or renew operation. Cannot be null or empty.</param>
private static void ReleaseRenew(IPConfigReleaseRenewMode mode, string adapterName)
{
var command = string.Empty;
if (mode is IPConfigReleaseRenewMode.ReleaseRenew or IPConfigReleaseRenewMode.Release)
command += $"ipconfig /release '{adapterName}';";
if (mode is IPConfigReleaseRenewMode.ReleaseRenew or IPConfigReleaseRenewMode.Renew)
command += $"ipconfig /renew '{adapterName}';";
if (mode is IPConfigReleaseRenewMode.ReleaseRenew6 or IPConfigReleaseRenewMode.Release6)
command += $"ipconfig /release6 '{adapterName}';";
if (mode is IPConfigReleaseRenewMode.ReleaseRenew6 or IPConfigReleaseRenewMode.Renew6)
command += $"ipconfig /renew6 '{adapterName}';";
PowerShellHelper.ExecuteCommand(command);
}
/// <summary>
/// Asynchronously adds an IP address to the specified network interface using the provided configuration.
/// </summary>
/// <param name="config">The configuration settings that specify the network interface and IP address to add. Cannot be null.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
public static Task AddIPAddressToNetworkInterfaceAsync(NetworkInterfaceConfig config)
{
return Task.Run(() => AddIPAddressToNetworkInterface(config));
}
/// <summary>
/// Adds an IP address to the specified network interface using the provided configuration.
/// </summary>
/// <remarks>If DHCP/static IP coexistence is enabled in the configuration, the method enables this
/// feature before adding the IP address. This method requires appropriate system permissions to modify network
/// interface settings.</remarks>
/// <param name="config">The network interface configuration containing the interface name, IP address, subnet mask, and DHCP/static
/// coexistence settings. Cannot be null.</param>
private static void AddIPAddressToNetworkInterface(NetworkInterfaceConfig config)
{
var command = string.Empty;
if (config.EnableDhcpStaticIpCoexistence)
command += $"netsh interface ipv4 set interface interface='{config.Name}' dhcpstaticipcoexistence=enabled;";
command += $"netsh interface ipv4 add address '{config.Name}' {config.IPAddress} {config.Subnetmask};";
PowerShellHelper.ExecuteCommand(command, true);
}
/// <summary>
/// Asynchronously removes the IP address specified in the configuration from the associated network interface.
/// </summary>
/// <param name="config">The configuration object that specifies the network interface and IP address to remove. Cannot be null.</param>
/// <returns>A task that represents the asynchronous remove operation.</returns>
public static Task RemoveIPAddressFromNetworkInterfaceAsync(NetworkInterfaceConfig config)
{
return Task.Run(() => RemoveIPAddressFromNetworkInterface(config));
}
/// <summary>
/// Removes the specified IP address from the given network interface configuration.
/// </summary>
/// <remarks>This method removes the IP address from the network interface using a system command. The
/// operation requires appropriate system permissions and may fail if the interface or IP address does not
/// exist.</remarks>
/// <param name="config">The network interface configuration containing the name of the interface and the IP address to remove. Cannot be
/// null.</param>
private static void RemoveIPAddressFromNetworkInterface(NetworkInterfaceConfig config)
{
var command = $"netsh interface ipv4 delete address '{config.Name}' {config.IPAddress};";
PowerShellHelper.ExecuteCommand(command, true);
}
#endregion
#region Events
/// <summary>
/// Occurs when the user cancels the current operation (e.g. UAC prompt).
/// </summary>
public event EventHandler UserHasCanceled;
private void OnUserHasCanceled()
{
UserHasCanceled?.Invoke(this, EventArgs.Empty);
}
#endregion
}