Enhancements from writing blog post
This commit is contained in:
parent
eccb226ccb
commit
0e6967cd33
1 changed files with 8 additions and 3 deletions
|
@ -19,10 +19,8 @@ namespace SBRL.Utilities
|
|||
foreach (NetworkInterface nic in nics)
|
||||
{
|
||||
Console.WriteLine("Id: {0}, Description: {1}", nic.Id, nic.Description);
|
||||
IPInterfaceProperties ipProps = nic.GetIPProperties();
|
||||
IPv4InterfaceProperties ip4Props = ipProps.GetIPv4Properties();
|
||||
if (nic.Id == targetInterfaceName)
|
||||
return ip4Props.Index;
|
||||
return nic.GetIPv4Index();
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue