Check if you on Wifi,LAN (office network) or using RAS at home (1 Viewer)

Derek

Registered User.
Local time
Today, 05:02
Joined
May 4, 2010
Messages
234
Hi guys,

My database is built in Access and it's been used by about 200 users . The users are aware of not using the system on Wifi or remotely but sometimes they still use wifi (sometimes they don't realize that their laptop is connected to Wifi at work ) so I want to build the functionality that when they open the system then it will check if they are on wifi /LAN or using RAS at home .

Can this be done ?

Thanks so much for looking at this .
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:02
Joined
Feb 28, 2001
Messages
26,996
Here is the issue you need to consider. Knowing that a particular network path is Remote Access Service (RAS) or uses WiFi or LAN connections requires you to visit each node to query its properties. Normally, the network setup is designed to HIDE this from a program because that network pipe is just another data channel.

Windows drivers use a style called device-independent I/O - which is to say that you don't say "go read this sector from the disk" - you just say "Read" and the driver figures out that if you didn't do a SEEK beforehand, you really meant "read next block" and it uses data stored "behind-the-scenes" to figure out and then perform your request. Similarly, network operations create logical connections (sometimes called "sockets") so that you don't have to diddle with protocols. The point of this long-winded discussion is that you are asking a question about something that the O/S is trying to keep from you because it doesn't want you trying to directly do something inconsistent with what it is doing "inside the little black box."

Within Windows, it is possible to determine the details of the first hop of your connection. WMI will certainly give you that kind of information and a few other tools would also do that. However, if the RAS connection is hardwired to your router and then that router goes wireless (i.e. satellite-based networking), THAT connection becomes harder to diagnose. It is not local to your system and thus doesn't "belong" to it.

When I was working with the U.S. Navy I had a laptop that I was allowed to bring home to establish a connection. For security reasons, I had to physically connect it to the back of my router even though it was a wireless router. (I had 4 hard-wired connectors so I could do this...) The way it could tell was whether I was on a connection that had a WiFi password (access key), which is within the scope of WMI "detective work."

I think the only thing you will be able to tell is whether your first hop is WiFi or LAN or RAS. After that, it might be a bit difficult. Basically, I guess I'm saying that what you can find out will be limited because in network terms, the only thing you "own" (in the Windows use of that term) is the connection on the back of your computer. After that, you need to be a network admin to be able to see that kind of info. On a home network (where RAS might be significant), that could be tricky.
 

isladogs

MVP / VIP
Local time
Today, 12:02
Joined
Jan 14, 2017
Messages
18,186
WMI is an extremely useful tool for finding out a wide variety of information about your computer hardware, software and network. I use it extensively in various apps such as my Access/Windows/Office365 Version Checker utility.

Amongst the enormous number of items it can detect are the details of any Ethernet and Wifi connections available on your workstation
However, AFAIK it cannot detect whether you are actually using a Wifi connection. I tried to find code for that purpose a couple of years ago with the intention of warning Access users on WiFi but the results weren't reliable.
My tests gave the same outcomes whether or not Wifi is actually switched on. I know Daniel Pineault also tried and failed.

So unless anyone knows better, I think you will be unsuccessful.
Having said that I'd love to be proved wrong about this.
 

Derek

Registered User.
Local time
Today, 05:02
Joined
May 4, 2010
Messages
234
Thanks for this. Can anyone please share the code that will check if laptop is connected to 'Wifi','RAS' or 'LAN'?
 

isladogs

MVP / VIP
Local time
Today, 12:02
Joined
Jan 14, 2017
Messages
18,186
Thanks for this. Can anyone please share the code that will check if laptop is connected to 'Wifi','RAS' or 'LAN'?

As already stated, I don't think its possible to do so using VBA but perhaps someone can tell us otherwise.
In the meantime, this article by Daniel Pineault may be worth reading: https://www.devhut.net/2016/09/24/access-back-end-location-wan-online-server-onedrive-dropbox/

And here's another link confirming my point that VBA can tell whether you have WiFi hardware installed but not whether its actually in use:
https://vbadud.blogspot.com/2010/05/how-to-check-internet-connectivity.html

If you do a Google search you will find several other similar posts/articles
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:02
Joined
Feb 28, 2001
Messages
26,996
I've been looking through some network-related sites and so far, I have not found anything that would identify the difference between RAS, LAN, WAN, and Wi-Fi. Just for those who are curious, the socket (assuming you could locate its data structure) does not contain this kind of info.

This is what a socket could tell you:

https://docs.microsoft.com/en-us/do....socket.getsocketoption?view=netframework-4.8

Specifically, these are the types of socket:

https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.sockettype?view=netframework-4.8

I also looked through the Windows Networking articles for enumerations that would include something to define the type of connection. If I had found anything promising I would have back-tracked it, but so far no joy. Here is where I found a lot of stuff, but skimming it did not produce a method to reach the desired goal.

https://docs.microsoft.com/en-us/uwp/api/windows.networking.connectivity#enums

I am certain that the information exists somewhere but I fear it may be buried away in a very obscure place - so obscure that it is harder to find the documentation for it than it would to eventually find the data.
 

Derek

Registered User.
Local time
Today, 05:02
Joined
May 4, 2010
Messages
234
Hi guys, the following code checks if the laptop is connected to the network but Can I add something in this so it will check Wifi and RAS too?

Code:
Option Explicit

Enum COMPUTER_NAME_FORMAT
    ComputerNameNetBIOS
    ComputerNameDnsHostname
    ComputerNameDnsDomain
    ComputerNameDnsFullyQualified
    ComputerNamePhysicalNetBIOS
    ComputerNamePhysicalDnsHostname
    ComputerNamePhysicalDnsDomain
    ComputerNamePhysicalDnsFullyQualified
End Enum

Declare Function GetComputerNameEx Lib "kernel32" Alias "GetComputerNameExA" ( _
ByVal NameType As COMPUTER_NAME_FORMAT, _
ByVal lpBuffer As String, _
ByRef lpnSize As Long) As Long

Sub test()

Dim buffer As String
Dim size As Long
Dim network_and_computer As String
Dim network_name As String

size = 255
buffer = Space(size)
GetComputerNameEx ComputerNameDnsFullyQualified, buffer, size
network_and_computer = Left$(buffer, size)

MsgBox network_and_computer

network_name = Right(network_and_computer, Len(network_and_computer) - InStr(1, network_and_computer, ".", vbTextCompare))

MsgBox network_name
If network_name = "ABC.net" Then
MsgBox "LAN"
End If
End Sub
 

isladogs

MVP / VIP
Local time
Today, 12:02
Joined
Jan 14, 2017
Messages
18,186
Hi Derek
You keep asking the same question without acknowledging previous comments by both myself and Doc that it appears not to be possible.

Have you read the links provided?
Have you found anything that suggests otherwise and that there may be a solution using vba?
If so suggest you post the link or any code you've found
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:02
Joined
Feb 28, 2001
Messages
26,996
Derek, I've continued to search but found no joy within that search. I'm still not 100% sure it can't be done, but nothing I can do directly through VBA will tell me whether I'm actually using a WiFi or LAN or WAN connection. (At least nothing so far.)

I admit that often it is a matter of asking the right question in the search. If that is the case here, then I have yet to ask the right question of my browser.

Here is a sort of backhanded approach because I can't find a more direct method. If you don't mind doing a little bit of parsing, you might be able to trigger a command shell to produce a file that would give you info. In the Windows Command Prompt, remember that the syntax > filename.txt takes the output of a utility program and stores it in the named file. Watch for the things I highlight in this stuff.

If you trigger NETSTAT -r > filename from the command prompt then the file you named would contain your routing tables. This info would differ from version to version for Windows, but here is what you might see:

Code:
C:\Users\Richard>netstat -r
===========================================================================
Interface List
 11...REDACTED ......Broadcom NetLink (TM) Gigabit Ethernet
 10...REDACTED ......Microsoft Wi-Fi Direct Virtual Adapter
 14...REDACTED ......Microsoft Wi-Fi Direct Virtual Adapter #2
 15...REDACTED ......Kaspersky Security Data Escort Adapter
  [COLOR="Red"]4[/COLOR]...REDACTED ......[COLOR="red"]Broadcom 802.11n Network Adapter[/COLOR]
  1...........................Software Loopback Interface 1
 13...00 00 00 00 00 00 00 e0 Microsoft Teredo Tunneling Adapter
===========================================================================

This part enumerates interfaces, some of which are hardware and some of which are not. Note that I have at least one 802.11 interface listed, and that is obviously the WiFi connection.

The next part of the display is the IPV4 routing table, which I am not going to repeat here because it would reveal some addresses that I won't be sharing. But there is also nothing there that would help in determining connections.

The next part is the IPV6 routing table, which tells you which connections you are actually using. Note that the tunneling adapter and loopback adapter are internal to the machine and therefore do not touch the net outside of the physical network adapter.


Code:
IPv6 Route Table
===========================================================================
Active Routes:
 If Metric Network Destination      Gateway
  [COLOR="red"]4[/COLOR]    311 ::/0                     REDACTED
  1    331 ::1/128                  On-link
 13    331 2001::/32                On-link
 13    331 REDACTED
                                    On-link
  [COLOR="red"]4[/COLOR]     71 REDACTED  REDACTED
  [COLOR="red"]4 [/COLOR]   311 REDACTED  On-link
  [COLOR="red"]4[/COLOR]    311 REDACTED
                                    On-link
  [COLOR="red"]4[/COLOR]    311 REDACTED
                                    On-link
  [COLOR="red"]4[/COLOR]    311 REDACTED
                                    On-link
  [COLOR="red"]4[/COLOR]    311 fe80::/64                On-link
 13    331 fe80::/64                On-link
 13    331 REDACTED
                                    On-link
  [COLOR="red"]4[/COLOR]    311 REDACTED
                                    On-link
  1    331 ff00::/8                 On-link
  [COLOR="red"]4[/COLOR]    311 ff00::/8                 On-link
 13    331 ff00::/8                 On-link
===========================================================================

The left-most column tells you which links are being used (refer to first portion of display).

There is another tool you might use: IPCONFIG /ALL will list your adapters and their states. Again, you would have to parse this out, but IPCONFIG /ALL >filename would give you something you could then read.

Code:
C:\Users\Richard>ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : REDACTED
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : REDACTED.net

Ethernet adapter Ethernet:

   [COLOR="red"]Media State . . . . . . . . . . . : Media disconnected[/COLOR]
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Broadcom NetLink (TM) Gigabit Ethernet
   Physical Address. . . . . . . . . : REDACTED
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

{redacted}

Ethernet adapter Ethernet 2:

   [COLOR="red"]Media State . . . . . . . . . . . : Media disconnected[/COLOR]
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Kaspersky Security Data Escort Adapter
   Physical Address. . . . . . . . . : REDACTED
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . : REDACTED.net
   Description . . . . . . . . . . . : Broadcom 802.11n Network Adapter
   Physical Address. . . . . . . . . : REDACTED
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IPv6 Address. . . . . . . . . . . : REDACTED
   Lease Obtained. . . . . . . . . . : Saturday, December 28, 2019 3:04:58 PM
   Lease Expires . . . . . . . . . . : Monday, January 27, 2020 3:04:56 PM
   IPv6 Address. . . . . . . . . . . : REDACTED
   Temporary IPv6 Address. . . . . . : REDACTED
   Link-local IPv6 Address . . . . . : REDACTED
   IPv4 Address. . . . . . . . . . . : 192.168.REDACTED(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Friday, December 20, 2019 12:36:00 AM
   Lease Expires . . . . . . . . . . : Tuesday, December 31, 2019 9:43:28 PM
   Default Gateway . . . . . . . . . : REDACTED
                                       192.168.1.254
   DHCP Server . . . . . . . . . . . : 192.168.1.254
   DHCPv6 IAID . . . . . . . . . . . : REDACTED
   DHCPv6 Client DUID. . . . . . . . : REDACTED
   DNS Servers . . . . . . . . . . . : REDACTED
                                       192.168.1.254
   NetBIOS over Tcpip. . . . . . . . : Enabled

Tunnel adapter Teredo Tunneling Pseudo-Interface:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Teredo Tunneling Adapter
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   IPv6 Address. . . . . . . . . . . : REDACTED
   Link-local IPv6 Address . . . . . : REDACTED
   Default Gateway . . . . . . . . . :
   DHCPv6 IAID . . . . . . . . . . . : REDACTED
   DHCPv6 Client DUID. . . . . . . . : REDACTED
   NetBIOS over Tcpip. . . . . . . . : Disabled

Note in this chunk of display that the one I/F that was NOT in "media disconnected" state had details not available for the ones with disconnected media.

If you create and capture those files it would be possible to read them to determine which interface you are using as long as you are only using one I/F.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:02
Joined
Oct 29, 2018
Messages
21,357
Hi. Pardon me for jumping in, but I was just wondering about one of the OP's requirements. Is there a separate hardware adapter for RAS connections? If not, then I wonder how the OP can determine that part. Just thinking out loud...
 

Micron

AWF VIP
Local time
Today, 08:02
Joined
Oct 20, 2018
Messages
3,476
Just wondering if something like Citrix would make the whole exercise moot? The fe and be are on the network server. If you link remotely, the fe and be are still on the network server, thus no WIFI.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:02
Joined
Feb 28, 2001
Messages
26,996
Actually, it is a very good question.

It took me a bit of skull sweat (and more than a modicum of luck) to stumble onto this way to dig out that I was actually using the WiFi, as demonstrated in the IPV6 routing tables. Where I highlighted the connections, it was clear they went through the WiFi.

The problem with RAS is that it is a type of encapsulation. I don't know how to tell from what I've found so far whether something is RAS or something else. The whole purpose of encapsulation is so that you don't know and don't need to know how a particular connection works. It just does. Note that not only Windows takes that approach. Every system TCP/IP stack I've ever seen hides that sort of thing from you because if you are Joe average user, you don't care.

Some options under IPCONFIG and NETSTAT discuss protocols. I won't bet hard cash on this, but I suspect that if someone actually HAS an RAS set up, something in one of the options of those utilities might be useful.

Here, my problem of taking it to the next step is that I have no RAS partner with which to form such a connection, so I can't test it.

Derek, this is the best I can do at this time, and I'm digging deep to get this much. The problem comes from the fact that the network protocols don't WANT to be seen, so there is no easy way to actually get to them.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:02
Joined
Feb 28, 2001
Messages
26,996
Micron, it isn't that simple. True, the FE-to-BE link is not going to crash on you, but there is another one that might - the session-to-FE link would still be on WiFi, so if you crash the session 'cause the WiFi burps, you have a hung session that will eventually have to be resolved. If you have a record open in a form and the session drops, you have a potentially locked record (depending on how you implemented the form) and potentially pending but as-yet unsaved data on that form. This is how corruption creeps in. Granted, not nearly so likely for the Citrix case as for a FE/BE directly over WiFi - but still a non-zero chance of an upset.
 

Micron

AWF VIP
Local time
Today, 08:02
Joined
Oct 20, 2018
Messages
3,476
the session-to-FE link would still be on WiFi, so if you crash the session 'cause the WiFi burps, you have a hung session that will eventually have to be resolved.
Pretty sure this happened to me more than once and all you need to do is log back in. Re-establishing the connection should put you right back where you were - unless you had a timer event or something that attempted to close that form or db. I used Citrix from home for years, sometimes working on a db in development, sometimes using established db's. I don't ever recall any issues occurring and I was even using WIFI. If users in the OP's business environment are using a db remotely then the potential for corruption should exist regardless, just more so in some methods. Citrix wasn't suggested as a means of preventing corruption, just as a means of preventing other remote connections while still allowing local ones. If it happens because of something on the other end, then that something ought to be possible to happen when the db is actually used locally.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:02
Joined
Feb 28, 2001
Messages
26,996
Micron, this is going to depend on the OP's business environment. As it happens, if you follow modern security guidelines, you can log back in to another session but that first session is dangling dead because modern IT practice is to disallow a RECONNECT operation.

If his IT folks set up group policy that way or if the Citrix admin sets it up that way, that is a dead session the moment the WiFi drops the connection.

There ARE ways of putting a timer on a form so that if it hangs for more than X minutes, you have it do a Form Undo operation followed by a Form Close and an Application Quit. That would at least protect the BE file. But getting back into that session depends on the site's Group Policy and Network Policy which is an unknown for us.

Note: At the U.S. Navy site, RECONNECT was disallowed even for Citrix.
 

Users who are viewing this thread

Top Bottom