Enhancements from writing blog post

This commit is contained in:
Starbeamrainbowlabs 2016-10-25 20:35:45 +01:00
parent eccb226ccb
commit 0e6967cd33
1 changed files with 8 additions and 3 deletions

View File

@ -19,10 +19,8 @@ namespace SBRL.Utilities
foreach (NetworkInterface nic in nics) foreach (NetworkInterface nic in nics)
{ {
Console.WriteLine("Id: {0}, Description: {1}", nic.Id, nic.Description); Console.WriteLine("Id: {0}, Description: {1}", nic.Id, nic.Description);
IPInterfaceProperties ipProps = nic.GetIPProperties();
IPv4InterfaceProperties ip4Props = ipProps.GetIPv4Properties();
if (nic.Id == targetInterfaceName) if (nic.Id == targetInterfaceName)
return ip4Props.Index; return nic.GetIPv4Index();
} }
throw new Exception($"Error: Can't find network interface with the name {targetInterfaceName}."); throw new Exception($"Error: Can't find network interface with the name {targetInterfaceName}.");
} }
@ -51,6 +49,13 @@ namespace SBRL.Utilities
} }
} }
} }
public static int GetIPv4Index(this NetworkInterface nic)
{
IPInterfaceProperties ipProps = nic.GetIPProperties();
IPv4InterfaceProperties ip4Props = ipProps.GetIPv4Properties();
return ip4Props.Index;
}
} }
} }