Detecting WiFi security settings

308 views
Skip to first unread message

Kai Bolay

unread,
Feb 18, 2017, 5:43:00 PM2/18/17
to Tasker
Hi!

I'm trying to create a task to automatically connect to a VPN when joining an unsecured (open) WiFi network (and disconnect whenever changing to a secured WiFi network or cellular).

I neither want to blacklist known "secure" networks nor whitelist known "insecure" networks using SSID or MAC address. Instead I want to check the security status (WEP, WPA_PSK, WPA_EAP, or NONE) of the network. While connected to a network with security status NONE I want to be connected via VPN.

Any tips?

I think Tasker might need to introduce an additional variable since neither %WIFI nor %WIFII contains the security status.

  Thanks, Kai

Christopher Scott

unread,
Feb 19, 2017, 12:19:04 AM2/19/17
to Tasker
Kai,

Let's make sure I understand the flow of what you are trying to do:

1. Android device connects to a WiFi network, whether it is secure or not.

2. Upon connect, a Tasker profile fires.

3. The child task checks if the new WiFi connection is secure.

3a. If no, the task connects to a VPN.

3b. If yes, Tasker retains the connection without further action.

Do I have that correct?

Kai Bolay

unread,
Feb 19, 2017, 5:27:08 AM2/19/17
to Tasker
Christopher,

Yes, that's exactly what I want to happen.

  Kai

Christopher Scott

unread,
Feb 20, 2017, 8:27:13 PM2/20/17
to Tasker
Kai,

I haven't forgotten you.

For the life of me, I can't figure out why this is so hard without using just a couple of activities, but, alas it is.

I'm currently working on a task for you. The task will --


(1) Grab the name (ssid) of the network you are on.

(2) Determine if the network implements either WAP and/or WAP2.

(3) Return a variable telling you if the network is secure or not. (If you need, I can include the the network's other available security protocols.)

One thing I'm not understanding, tho. If you are connected to a secure network, doesn't that mean you know its secure because you had to set up the connection?

If that is the case, do you really need this task to throw a warning when connected to an unsecure network rather than just telling you if your current network is / isn't secure? (Android does that natively whenever you connect to an unsecured neywork.) If so, how would you like the task to execute, (1) via a profile that fires when you connect to a wifi network or (2) when you call the task internally from another task?

Think of the two options this way.

Option 1
Profile -- Connect to a Wifi Network

Run Task: Check Network Security

--or --

Option 2

A1: <<Perform an activity>>
A2: <<Perform the next activity>>
A3: Perform Task - Check Network Security
A4: <<Perform another activity>>

I'm happy to set it any way you want it.

As for the reason I'm not done with this yet, I am trying to sort through a quirk in the data pulled by one of the addons I am using - AutoTools.

Subtle hint, there - you'll want to go download AutoTools from the app store, if you don't already have it. You'll need it to run the task I am building.

And when I get this thing all worked out, I promise to walk you through it.

Kai Bolay

unread,
Feb 22, 2017, 2:04:23 AM2/22/17
to tas...@googlegroups.com
Hi!

Thanks for working on this.

I don't quite understand your question (maybe because I just started
using Tasker): You ask if I "really need this task to throw a warning
when connected to an unsecure network rather than just telling you if
your current network is / isn't secure?" - I didn't ask for any
"warning". Why do you think I wanted a warning?

Let me try to restate what I want: If I'm connected to an
open/unsecured network I want to automatically use VPN. Otherwise
(secured WiFi or connection via the cell network) I don't want to use
the VPN.

I have tasks to connect to the VPN and to disconnect from the VPN. I
think need to work with the existing "WiFi Connected" profile and make
the connection to VPN conditional in the WiFi state. The "if"
condition requires me to enter a variable name, operator, and value.
So what I need is some way to populate a variable with the security
status of the currently (freshly) connected WiFi network. I assume
that I need a task to set that variable - or Tasker needs to be
updated to provide that variable natively. In summary:

Profile: "WiFi Connected"
- Enter tasks:
1) Set variable to security status of current WiFi connection (not
needed if Tasker is updated to natively provide a variable with that
info)
2) If variable indicates no security execute task "Connect to VPN"
- Exit tasks:
1) Disconnect from VPN (which should be a no-op if already disconnected)

Thanks again,
Kai
> --
> You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/Cbie3XEMZRY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
> Visit this group at https://groups.google.com/group/tasker.
> For more options, visit https://groups.google.com/d/optout.

Sean Williams

unread,
Feb 23, 2017, 1:31:39 PM2/23/17
to Tasker
I neither want to blacklist known "secure" networks nor whitelist known "insecure" networks using SSID or MAC address. Instead I want to check the security status (WEP, WPA_PSK, WPA_EAP, or NONE) of the network. While connected to a network with security status NONE I want to be connected via VPN.

Any tips?


Nice idea, it could be a useful addition to a project I have been working on.

After testing I found the best way to determine if a networks secure is to use key management on a device configured network.


Java - getConfigNets - isSecure (555)
A1: Test Net [ Type:Wifi SSID Data: Store Result In:%conssid ]
A2: If [ %conssid !~ <*> & %conssid Set ]
A3: Java Function [ Return:wifiser Class Or Object:CONTEXT Function:getSystemService
{Object} (String) Param:wifi Param: Param: Param: Param: Param: Param: Continue Task After Error:On ]
A4: Java Function [ Return:configlist Class Or Object:wifiser Function:getConfiguredNetworks
{List}() Param: Param: Param: Param: Param: Param: Param: ]
A5: Java Function [ Return:%size Class Or Object:configlist Function:size
{int} () Param:ssid Param: Param: Param: Param: Param: Param: ]
A6: Variable Subtract [ Name:%size Value:1 Wrap Around:0 ]
A7: For [ Variable:%idx Items:0:%size ]
A8: Java Function [ Return:network Class Or Object:configlist Function:get
{Object} (int) Param:%idx Param: Param: Param: Param: Param: Param: ]
A9: Java Function [ Return:%ssid Class Or Object:network.SSID Function:toString
{String} () Param: Param: Param: Param: Param: Param: Param: ]
A10: If [ %ssid eq "%conssid" ]
<allowedKeyManagement>
A11: Java Function [ Return:%allwdkeymgmt Class Or Object:network.allowedKeyManagement Function:toString
{String} () Param: Param: Param: Param: Param: Param: Param: ]
A12: End If
A13: End For
A14: If [ %allwdkeymgmt ~ *0* ]
A15: Flash [ Text:Network Not Secure Long:Off ]
A16: Else
A17: Flash [ Text:Network Secure Long:Off ]
A18: End If
A19: Else
A20: Flash [ Text:Wifi SSID Unavailable Long:Off ]
A21: End If


The task will display not secure if there is no security or only WEP (likely due to wep being cracked). Otherwise it will return secure.

You should run the code once the network is connected, so in your 'connected' enter Task.

The pattern match on the integer is because my device returns the value in curly brackets {}.

Kai Bolay

unread,
Feb 26, 2017, 11:15:39 PM2/26/17
to tas...@googlegroups.com, Sean Williams
Hi Sean!

Thanks a lot for the task you created. Now I have a total n00b
question: Is there a way to import that task into Tasker? Or do I need
it in XML format? If so, could you send me the XML?

Thanks, Kai

PS: How did you create the task? Seems very tedious to manually create
those Java Functions. Is there a simpler/better way than typing them
into Tasker's UI?

Sean Williams

unread,
Feb 28, 2017, 3:45:07 PM2/28/17
to Tasker
Hi,

Thanks a lot for the task you created. Now I have a total n00b
question: Is there a way to import that task into Tasker? Or do I need
it in XML format? If so, could you send me the XML?

I'll post the xml (need to be at my computer).


PS: How did you create the task? Seems very tedious to manually create
those Java Functions. Is there a simpler/better way than typing them
into Tasker's UI?

Not that I know of. It's a short task after a bit of practice you'll be upto speed!

Sean Williams

unread,
Feb 28, 2017, 4:29:48 PM2/28/17
to Tasker, trendyte...@gmail.com
Java___getConfigNets___isSecure.tsk.xml

Abdullah Alahdal

unread,
Mar 2, 2017, 11:38:35 AM3/2/17
to Tasker
Kai,

How you connect to VPN? Is it work VPN or something else like OpenVPN.

Kai Bolay

unread,
Mar 2, 2017, 12:37:22 PM3/2/17
to tas...@googlegroups.com, alahda...@gmail.com
Abdullah,


To connect/disconnect I created two simple tasks:

Start OpenVPN
  A1: Send Intent [ 
          Action:android.intend.action.VIEW
          Cat:Browsable
          Mime Type:
          Data:
          Extra:net.openvpn.openvpn.AUTOSTART_PROFILE_NAME: vps.bolay.us [pixel]
          Extra:
          Extra:
          Package:net.openvpn.openvpn
          Class:net.openvpn.openvpn.OpenVPNClient
          Target:Activity
        ]

Stop OpenVPN
  A1: Send Intent [
          Action:android.intend.action.VIEW
          Cat:None
          Mime Type:
          Data:
          Extra:
          Extra:
          Extra:
          Package:net.openvpn.openvpn
          Class:net.openvpn.openvpn.OpenVPNDisconnect
          Target:Activity
        ]

I hope this helps.

  Kai

Bill Chen

unread,
Apr 13, 2017, 6:23:47 AM4/13/17
to Tasker
+1

This could be quite helpful.

The ScanResult object exposes the capabilities field which should contain all of these. Adding a regex match field for this to the WiFi related dialogues will also make this easier to use.

A.M. Heijboer

unread,
Jun 10, 2017, 5:54:23 AM6/10/17
to Tasker, trendyte...@gmail.com
+1

This is really great, thank you so much!!


Op dinsdag 28 februari 2017 22:29:48 UTC+1 schreef Sean Williams:
Reference
Reply all
Reply to author
Forward
0 new messages