Firstly, there are some terms that you need to know. These sample numbers assume an IPv4 network.
- IP Address (192.168.1.1)
- Subnet Mask (255.255.255.0)
- network address (192.168.1.0)
- network interface card, network adapter (there can be several of these on one hardware card)
To find out which network the IP address belongs to, you need to calculate the network address. This is easy if you take your IP address (either as a byte [4], or in UInt64), and bitwise "and" it using a subnet mask.
using System; using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Net.Sockets; namespace ConsoleApplication { public static class ConsoleApp { public static void Main() { var nics = NetworkInterface.GetAllNetworkInterfaces(); foreach (var nic in nics) { var ipProps = nic.GetIPProperties();
Note that you can have multiple IP addresses on the same network that the VPN can have a submask of 255.255.255.255 (so that network address == IP address), etc.
sisve source share