0

OS: Windows, Language: C++

I'm implementing this use case: When a user starts my software, the software needs to know if his/her PC is currently connected to a specified network (e.g. a college campus intranet). Only if yes, some of the software's features are enabled.

I'm new to this area and really cannot tell the reliable programmatic way. Function GetComputerNameEx (https://msdn.microsoft.com/en-us/library/windows/desktop/ms724301%28v=vs.85%29.aspx) seems promising. If this function works for my use case, what data obtained by this function can I rely on?

Thanks in advance!

  • Take a look at [this question](http://stackoverflow.com/questions/4683545/obtaining-currently-connected-network-name-ssid-in-c). – Mewa Mar 16 '15 at 22:27
  • Thanks Mewa. I will try it. But what if the PC is connected by cable? In this case, is the domain name good to use? – user3552888 Mar 16 '15 at 23:05

2 Answers2

1

One of the more reliable indicators is the presence of certain MAC addresses: these are visible only inside a LAN, not on the global internet. Even on NAT'ted IPv4 networks a MAC address will be globally unique.

On Windows you can try SendArp

MSalters
  • 173,980
  • 10
  • 155
  • 350
0

I think you can only find out if this pc is connected to Internet or not. You can't find a difference between a college interanet or some home network, using a hub.

You must check this connection by pinging a known good server like google.com, pinging your authserver, or any way that you can be sure this machine is connected to the internet.

#include <iostream>
#include <windows.h> 
#include <wininet.h>
using namespace std;

int main(){

  if(InternetCheckConnection(L"http://www.google.com",FLAG_ICC_FORCE_CONNECTION,0)
  {
        cout << "connected to internet";
  }

  return 0;
}

refrence : by Nayana Adassuriya

Community
  • 1
  • 1
GOWB
  • 1
  • 2
  • In cases at least they can be differentiated by the PC's public IP address. https://msdn.microsoft.com/en-us/library/windows/desktop/ms738520%28v=vs.85%29.aspx. But to me, reliability of public IP address is questionable. – user3552888 Mar 16 '15 at 22:53
  • @user3552888 can you elaborate on why it's questionable? – Paweł Stawarz Mar 17 '15 at 00:23
  • @Paweł Stawarz: let me use college intranet as the example. Two departments have their own LANs. Only PCs connected to one LAN have access to those features. But they may share the same public IP address. Please correct me if I'm wrong. – user3552888 Mar 17 '15 at 00:59
  • @user3552888 but they both indeed are a part of the college as a whole. Isn't that exactly what you're looking for? Do you need to distinguish different departments as well? – Paweł Stawarz Mar 17 '15 at 01:05