-
Jan 20th, 2014, 12:57 PM
#1
Thread Starter
Member
anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
Hi
Creating an app for my customers which will check some security settings i.e. av enabled, up-to-date, windows updates etc etc
Is there anyway of detecting what wireless security is being used on current wireless connection - i.e is it WEP, WPA. WPA, open etc
-
Jan 20th, 2014, 02:04 PM
#2
Hyperactive Member
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
I don't see the reason why any app would need to identify what security is being used on a wireless network which your program would only be sitting behind and not interacting with. So my first question is why do you need to know what type of security it is using, and instead wouldn't it make more sense to try to listen to the network traffic? No AV, that I'm aware of monitors any such information.
If you don't mind, but can you elaborate on why you need to know such information, or how your app intends to use such information and why it needs to?
-
Jan 20th, 2014, 02:15 PM
#3
Thread Starter
Member
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
The app I am creating is to perform "health checks" on my customers PC - it is basically automating a lot of things I check manually - so currently it checks what AV is installed, and whether enabled and up-to-date, UAC settings, automatic update settings and much more
The final area I need to add is to show what security the wireless connection is using - so if it is connected to an unsecured "open" router then it would alert them - if it is WPA2 then it would show green tick to show passed that particular test
-
Jan 20th, 2014, 02:49 PM
#4
Hyperactive Member
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
http://www.codeproject.com/Articles/...pting-Wireless
That is a starting point but you also need to convert the code into VB.Net. This is not something you can do easily - Getting the status of the wireless connection. However, you can use this to convert some of it: http://www.developerfusion.com/tools.../csharp-to-vb/
Also lookup Managed WiFi API on Google. You will most likely need it unless there is another way to find such information? You can play with: My.Computer.Network.IsAvailable - but without converting the C code, I think you're on your own on this. As I already seen the guys at msdn forums won't help you either. No surprise there though!
-
Jan 20th, 2014, 02:53 PM
#5
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
You have to PInvoke the Wlan functions such as WlanOpenHandle, WlanEnumInterfaces, WlanGetAvailableNetworkList, WlanGetNetworkBssList, and WlanFreeMemory to get out the DOT11_CIPHER_ALGORITHM enumeration for your connection.
There is a managed code library with wrappers for these functions available at CodePlex written in C# which you can use. You just have to compile it and add a reference to it in your VB application.
Joacim Andersson
If anyone's answer has helped you, please show your appreciation by rating that answer.
I'd rather run ScriptBrix...
Joacim's view on stuff.
MVP
-
Jan 20th, 2014, 03:16 PM
#6
Thread Starter
Member
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
Thanks for your replies - think I need to do some reading then as looks quite complex - was hoping for an easier way to just pick up security used for current connection, sounds like that isn't going to happen then!
If anyone has any source or samples of using it in VB that would be handy, at least if in the language I know I might comprehend it easier
Cheers
-
Jan 20th, 2014, 03:25 PM
#7
Hyperactive Member
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
Sadly for you Wingers, most of this has already been done in C, but there is not a lot on this being covered in VB.Net - as its all a bit gray. However, I will dig around a little for you tonight and try and find you something useful and easier to use. But as said above, you are most likely, looking at converting this into VB.Net from C, and even at that, it won't be a sale through. If you don't hear back from me; you know i didn't find anything worth posting... Good luck
-
Jan 20th, 2014, 03:44 PM
#8
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
Why? I'll bet you use a lot of APIs where you don't know the exact inner working of them. Just download the project I linked to in my previous post, compile it and set a reference to it in your own project and use code similar to this:
Code:
Dim wifi As New NativeWifi.WlanClient()
For Each wlaninterface As NativeWifi.WlanClient.WlanInterface In wifi.Interfaces
Dim networks() As NativeWifi.Wlan.WlanAvailableNetwork = wlaninterface.GetAvailableNetworkList(0)
For Each network As NativeWifi.Wlan.WlanAvailableNetwork In networks
Select Case network.dot11DefaultCipherAlgorithm
Case Wlan.Dot11CipherAlgorithm.CCMP
'AES
Case Wlan.Dot11CipherAlgorithm.None
'None
Case Wlan.Dot11CipherAlgorithm.TKIP
'WPA
Case Wlan.Dot11CipherAlgorithm.WEP
'WEP with cipher key of any length
Case Wlan.Dot11CipherAlgorithm.WEP104
'WEP with 104-bit cipher key
Case Wlan.Dot11CipherAlgorithm.WEP40
'WEP with 40-bit cipher key
End Select
Next
Next
Joacim Andersson
If anyone's answer has helped you, please show your appreciation by rating that answer.
I'd rather run ScriptBrix...
Joacim's view on stuff.
MVP
-
Jan 20th, 2014, 03:45 PM
#9
Thread Starter
Member
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
Another way I could do it perhaps...
The command netsh wlan show interfaces shows the authentication of current connection i.e. WPA2-Personal
So perhaps I could pull the information from this somehow?
-
Jan 20th, 2014, 03:51 PM
#10
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
Why make it difficult? If there's a library, as JA already linked to, then use the library. Otherwise you are just reinventing the wheel.
My usual boring signature: Nothing
-
Jan 20th, 2014, 03:53 PM
#11
Thread Starter
Member
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
 Originally Posted by Joacim Andersson
Why? I'll bet you use a lot of APIs where you don't know the exact inner working of them. Just download the project I linked to in my previous post, compile it and set a reference to it in your own project and use code similar to this:
Code:
Dim wifi As New NativeWifi.WlanClient()
For Each wlaninterface As NativeWifi.WlanClient.WlanInterface In wifi.Interfaces
Dim networks() As NativeWifi.Wlan.WlanAvailableNetwork = wlaninterface.GetAvailableNetworkList(0)
For Each network As NativeWifi.Wlan.WlanAvailableNetwork In networks
Select Case network.dot11DefaultCipherAlgorithm
Case Wlan.Dot11CipherAlgorithm.CCMP
'AES
Case Wlan.Dot11CipherAlgorithm.None
'None
Case Wlan.Dot11CipherAlgorithm.TKIP
'WPA
Case Wlan.Dot11CipherAlgorithm.WEP
'WEP with cipher key of any length
Case Wlan.Dot11CipherAlgorithm.WEP104
'WEP with 104-bit cipher key
Case Wlan.Dot11CipherAlgorithm.WEP40
'WEP with 40-bit cipher key
End Select
Next
Next
Thanks Joacim - for some reason though it was going to be more complex than that - will have a go now!!
-
Jan 20th, 2014, 04:19 PM
#12
Thread Starter
Member
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
Okay that seems to sort of work - but it gives me back 4 results on a laptop with only 1 wireless card/connection and none of them seem to tally with what the connection is - i.e. it comes back AES more then once, when connection is WPA2-Personal
-
Jan 20th, 2014, 04:48 PM
#13
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
WPA2 uses AES, so it's the same thing, I didn't list all of the enumeration values in my Select Case above, there are others and you can read on what they are here. A single wireless card can have several interfaces or access points.
Most routers can be setup to use WPA2 with AES only or AES+TKIP to be backward compatible with WPA (which uses the TKIP encryption).
Last edited by Joacim Andersson; Jan 20th, 2014 at 04:59 PM.
Joacim Andersson
If anyone's answer has helped you, please show your appreciation by rating that answer.
I'd rather run ScriptBrix...
Joacim's view on stuff.
MVP
-
Jan 20th, 2014, 05:09 PM
#14
Thread Starter
Member
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
 Originally Posted by Joacim Andersson
WPA2 uses AES, so it's the same thing, I didn't list all of the enumeration values in my Select Case above, there are others and you can read on what they are here. A single wireless card can have several interfaces or access points.
Most routers can be setup to use WPA2 with AES only or AES+TKIP to be backward compatible with WPA (which uses the TKIP encryption).
Thanks, that makes sense
Still confused as to why it comes back with four different results for one card (AES,AES,None,AES) - would be nice just to get the one result for the current connection to the router
Can I also get signal strength using this library?
-
Jan 20th, 2014, 05:38 PM
#15
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
 Originally Posted by wingers
Can I also get signal strength using this library?
I don't know since I've never actually used it. I just wrote that example up for your benefit. Have a look around the library and see what you can find yourself. (The object browser is an excellent tool).
Joacim Andersson
If anyone's answer has helped you, please show your appreciation by rating that answer.
I'd rather run ScriptBrix...
Joacim's view on stuff.
MVP
-
Jan 20th, 2014, 06:33 PM
#16
Thread Starter
Member
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
 Originally Posted by Joacim Andersson
I don't know since I've never actually used it. I just wrote that example up for your benefit. Have a look around the library and see what you can find yourself. (The object browser is an excellent tool).
Think I may have found it - had never use the object browser before, very handy
Thanks again for all your help and pointing me in the right direction, at least I have something to play with now
-
Jan 20th, 2014, 06:49 PM
#17
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
The F2 key opens the Object Browser (at least with the keyboard mapping I use in VS).
Joacim Andersson
If anyone's answer has helped you, please show your appreciation by rating that answer.
I'd rather run ScriptBrix...
Joacim's view on stuff.
MVP
-
Jan 21st, 2014, 02:47 PM
#18
Thread Starter
Member
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
Right, it appears the reason I am getting multiple results returned, is that the code is showing me encryption state of all networks it can see - where I want to just see encryption type (and SSID, signal strength and channel if possible) for the current connection
Been having a play, but any advise on how I can do this would be much appreciated!
-
Jan 21st, 2014, 04:34 PM
#19
Thread Starter
Member
Re: anyway of detecting what wireless security is being used i.e WPA2, WEP, open etc
gave up trying to understand native wifi API, as seemed to be returning wrong information on some Windows 8.1 machines
So went for my original idea of parsing result from netsh wlan show interface to get information I needed
Code below in case any use to anyone else
Code:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
' runs netsh wlan show interfaces and outputs result to string
Dim myprocess As New Process()
myprocess.StartInfo.FileName = "c:\windows\system32\netsh.exe"
myprocess.StartInfo.Arguments = "wlan show interfaces "
myprocess.StartInfo.UseShellExecute = False
myprocess.StartInfo.RedirectStandardOutput = True
myprocess.StartInfo.CreateNoWindow = True
myprocess.Start()
myprocess.WaitForExit()
Dim result As String = (myprocess.StandardOutput.ReadToEnd())
Dim result_encryption As String = String.Empty
Dim result_signalstrength As String = String.Empty
Dim result_SSID As String = String.Empty
Dim result_channel As String = String.Empty
' code below searches netsh results to find location of required information
Dim FindAuthentication As Integer
FindAuthentication = result.IndexOf("Authentication")
Dim FindSignalStrength As Integer
FindSignalStrength = result.IndexOf("Signal")
Dim FindSSID As Integer
FindSSID = result.IndexOf("SSID")
Dim FindChannel As Integer
FindChannel = result.IndexOf("Channel")
' this checks to see if error occured i.e. no wireless card or service not started - the error shown begins with "There" or "The" so we look for this in the string
' if okay then we display results by parsing the netsh results and returning the values we are after i.e. encryption type, signal strength, SSID and channel
If result.StartsWith("The", StringComparison.CurrentCultureIgnoreCase) Then
MsgBox("No wireless")
Else
result_encryption = result.Substring(FindAuthentication + 25, 18)
MsgBox("Encryption: " & result_encryption)
result_signalstrength = result.Substring(FindSignalStrength + 25, 5)
MsgBox("Signal Strength: " & result_signalstrength)
result_SSID = result.Substring(FindSSID + 25, 16)
MsgBox("SSID: " & result_SSID)
result_channel = result.Substring(FindChannel + 25, 3)
MsgBox("Channel: " & result_channel)
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|