Is there any way to check whether I'm connected via WLAN?

This forum is for general support of Xbase++
Post Reply
Message
Author
User avatar
SvenVazan
Posts: 12
Joined: Sun May 03, 2015 11:35 am

Is there any way to check whether I'm connected via WLAN?

#1 Post by SvenVazan »

Hey all,

Is there any way to detect whether my internet connection is connected through WLAN vs. LAN? We have certain parts of our software that should only be run through a wired interface, so I would like to warn or prevent users from using a wireless connection in certain modules.

Any ideas?

psc
Posts: 5
Joined: Thu Sep 29, 2016 11:48 am

Re: Is there any way to check whether I'm connected via WLAN

#2 Post by psc »

If you have the actual name of the interface ( you can get this from the "description" field when running ipconfig /all at the command prompt ), you can try this:

Make sure you stick this at the top somewhere

Code: Select all

#pragma library( "ascom10.lib" ) 

Code: Select all

PROCEDURE Main

local oWMI
local oCol
local bCol
local cStatus
bCol := {| oService  | cStatus := oService:getProperty( "NetConnectionStatus" ) }
oWMI := CreateObject( "WbemScripting.SWbemLocator" ):ConnectServer("Localhost", "root\cimv2")

//my hard-wired connection
oCol = oWMI:ExecQuery("Select * from Win32_NetworkAdapter Where Name = 'Intel(R) 82579LM Gigabit Network Connection'" )
ComEvalCollection( oCol , bCol )

? cStatus  //I see 2 when I run this, since I'm wired up
//my wireless connection

cStatus := NIL

oCol = oWMI:ExecQuery("Select * from Win32_NetworkAdapter Where Name = 'Dell Wireless 1820 802.11ac'" )
ComEvalCollection( oCol , bCol )

? cStatus //I see 7 when I run this, since I'm disconnected


RETURN
The other statuses are:
0 = “Disconnected”
1 = “Connecting”
2 = “Connected”
3 = “Disconnecting”
4 = “Hardware not present”
5 = “Hardware disabled”
6 = “Hardware malfunction”
7 = “Media disconnected”
8 = “Authenticating”
9 = “Authentication succeeded”
10 = “Authentication failed”
11 = “Invalid address”
12 = “Credentials required”

If you don't know the name of your adapter, or there's lots of different adapters, you'd have to enumerate them, which is a little more work. You can get the list of NIC's via this:

Code: Select all

local oWMI
local oCol
local bCol
local aStatus := {}
bCol := {| oService  | aadd( aStatus , oService:getProperty( "Name" ) ) }
oWMI := CreateObject( "WbemScripting.SWbemLocator" ):ConnectServer("Localhost", "root\cimv2")
oCol = oWMI:ExecQuery("Select * from Win32_NetworkAdapter" )
ComEvalCollection( oCol , bCol )
? aStatus
The names will usually have wireless, or wlan, or something like that in them. You can then check the status like above.
You can also root around for a SSID, I think, using this

Code: Select all

oWMI:ExecQuery("Select * from objMSNdis_80211_ServiceSetIdentifierSet" ) 
but I'm not sitting in front of a box with an active WLAN connection, so I can't really tinker with objMSNdis_80211_ServiceSetIdentifierSet today.

psc

Post Reply