I'm planning on developing a desktop application that can provide various features depending on which networks a system is connected to, such as setting up routing.
So I'm looking for a way to identify and assign a human-friendly label to the network that an interface / adapter is connected to. By that I mean labels like "Home Wi-Fi", "XYZ's Wi-Fi", "Office ethernet", or in the case of virtual interfaces, things like "XYZ Company VPN", "VPN service X's New York servers", "VPN service Y's Paris server", and so on. I expect users of this app to be able to label the networks themselves. I just need a way of reliably identifying them and telling them apart.
To that end, what kind of information can I get from a network interface to recognize a specific network, and distinguish multiple networks from each other?
In terms of things that don't require making outgoing requests, off the top of my head there's:
- Physical interface type (ethernet, Wi-Fi, etc.)
- Local IP address & netmask
- Gateway
- DNS servers
...though those don't seem like a reliable way of accomplishing this. Different unrelated networks can share the same local IP address range, gateway IP, and even DNS servers.
That leaves things that require making some outgoing requests, like:
- public IP address
- local domain name (if any)
- seeing what other systems that are connected on the same network (perhaps identified by MAC address)
Those don't strike me as super reliable either, since public IP addresses can change, and not every local network has its own domain name or servers that are reliably connected to it.
What I'd prefer to avoid is any OS or application specific approach, like looking at system settings or the settings for a third party VPN client, since there's simply too many different ways to configure this sort of thing across all the major operating systems and their networking clients.
Is there an approach that works reliably? Perhaps some combination of all of these?