My Wifi Keys (fr-uk-de compatible)

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 340
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

My Wifi Keys (fr-uk-de compatible)

Post by ar-s »

Image

Hi there,

I propose you a small software that I made to display the wifi keys registered in a local network.
I made it because when I go to my customers, either they don't know the wifi key and have to look for it in the box interface or behind the box, or the key is 3miles long which makes me waste time.
So this little software will show you the key of the SSID of your local network and will copy it in the clipboard.

UPDATE v1.01
Should now work with english, german or french windows.


- Windows Only

Notes
- Wifi connection must be your primary connection
- You must have a wifi interface (or wifi usb key connected)
- The service : WLAN auto config service must be at least on "automatic" (which is logically the case).
Thanks for your feedback.

Translated with www.DeepL.com/Translator (free version)

Download : MyWifi.zip

Code: Select all

; My Wifikeys
; My Wifikeys
; By Ar-S // 2021-09-21
; v1.01 adding english findstring strings.
; Thanks to Barry - Englsih keyword
; Thanks Cyllceaux - Deutch keyword

NewList ssid.s()

; Catch SSID
param$ = "wlan show profiles"
p=RunProgram("netsh",param$,"",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)

If p
    
    While ProgramRunning(p)
        If AvailableProgramOutput(p)
            t$ = ReadProgramString(p)
            n1=FindString(t$,":")
            If n1
                n2=Len(t$)
                r$=Mid(t$,n1+1,n2-n1)
                AddElement (ssid())
                ssid() = r$
             EndIf
        EndIf
        err$ = ReadProgramError(p)
        If err$
            o$+"<ERR> " + err$ +#CRLF$
        EndIf
    Wend
    
    CloseProgram(p)

EndIf


If ListSize (ssid()) = 0
    MessageRequester("Erreur","No wifi is connected on this machine or it is not the main connection."+Chr(10)+"This program will end",0)
    End
EndIf

If OpenWindow(0, 0, 0, 360, 60, "LDV MULTIMEDIA MY WIFIKEYS v1.01", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    GO = 0
    ComboBoxGadget(1,1,1,358,30)
    ForEach ssid()
        AddGadgetItem(1, -1, ssid() )
    Next
    RemoveGadgetItem(1,0)
    
    SetGadgetState(1,0)
    StringGadget(2,1,32,358,30,"",#PB_String3D_ReadOnly)
    
    
    Repeat
        Event = WaitWindowEvent()
        
        
        Select EventGadget()
            Case 1
                
                If EventType() = #PB_EventType_Change
                    ssid$ = GetGadgetText(1)
                    param$="wlan show profile name="+Chr(34)+Trim(ssid$)+Chr(34)+" key=clear"
                    p2=RunProgram("netsh",param$,"",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)
                    
                    If p2
                        r2$ = ""
                        
                        While ProgramRunning(p2)
                            If AvailableProgramOutput(p2)
                                t$ = ReadProgramString(p2)+#CRLF$
                                FR = FindString(t$,"Contenu de la cl",1,#PB_String_NoCase) ; français
                                UK = FindString(t$,"key content",1,#PB_String_NoCase)      ; English
                                DE = FindString(t$,"sselinhalt",1,#PB_String_NoCase)       ; Deutch
                                
                                If FR <> 0
                                    r2$ = t$
                                ElseIf  UK <> 0
                                    r2$ = t$
                                ElseIf DE <> 0
                                     r2$ = t$   
                                EndIf
                                
                                
                                If r2$ <> ""
                                    n1=FindString(r2$,":")
                                    n2=Len(r2$)
                                    r2$=Mid(r2$,n1+1,n2-n1)
                                Else
                                    r2$ = "No active wifi detected :[ "
                                EndIf
                                
                            EndIf
                            err$ = ReadProgramError(p2)
                            If err$
                                o$+"<ERR> " + err$ +#CRLF$
                            EndIf
                        Wend
                        
                        CloseProgram(p2)

                    Else
                        Debug "erreur"
                    EndIf
                    SetGadgetText(2,"Wifi key : "+ r2$)
                    SetClipboardText(r2$)
                EndIf
                
        EndSelect
    Until Event = #PB_Event_CloseWindow
EndIf

Last edited by ar-s on Sat Sep 25, 2021 4:10 pm, edited 2 times in total.
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: My Wifi Keys

Post by Denis »

Vraiment Sympa!

Image
A+
Denis
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: My Wifi Keys

Post by BarryG »

ar-s wrote: Thu Sep 23, 2021 8:09 amWLAN automatic configuration service must be at least on "automatic"
Where do I find this setting in my router? What name should I search for?

Because your code doesn't reveal any keys for me:

Image

I have a Netgear router and my PC connects to it via wi-fi only (no ethernet cable).
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: My Wifi Keys

Post by firace »

BarryG wrote: Fri Sep 24, 2021 8:40 am
ar-s wrote: Thu Sep 23, 2021 8:09 amWLAN automatic configuration service must be at least on "automatic"
Where do I find this setting in my router? What name should I search for?

Because your code doesn't reveal any keys for me:

Image

I have a Netgear router and my PC connects to it via wi-fi only (no ethernet cable).
This is a Windows service.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: My Wifi Keys

Post by BarryG »

firace wrote: Fri Sep 24, 2021 8:50 amThis is a Windows service.
Is it this one?

Image
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: My Wifi Keys

Post by firace »

BarryG wrote: Fri Sep 24, 2021 8:55 am
firace wrote: Fri Sep 24, 2021 8:50 amThis is a Windows service.
Is it this one?
Yes I think so. @ar-s please can you confirm?
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: My Wifi Keys

Post by Marc56us »

Hi,

If the interface does not display anything (no error), it means that the default connection is not on the WiFi card, but on another one (network cable)

This program show the password of the active connection only (default connection).
Of course this works only if your are connected on this connection.
It is likely that an admin account is required ?

As seen on RunProgram line, this send command line:

Code: Select all

netsh wlan show profile name=<SSID WiFi> key=clear
Edit: After testing in different cases (Wifi card on/off and internet connection on/off) I get different results.
I have a cable (fiber) and Wifi connection and can switch from one to the other.

:wink:
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: My Wifi Keys

Post by BarryG »

I tried with and without admin rights, and still no key is shown; and it's definitely wi-fi to my current online connection. Maybe it's a router security thing; I don't know. I don't know how networks work. If anything, it shows the code can't be relied upon, because if I were one of ar-s's customers, I'd be saying "it's not showing any key" and frustrating him. Hehe.
Last edited by BarryG on Fri Sep 24, 2021 10:23 am, edited 1 time in total.
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My Wifi Keys

Post by Cyllceaux »

the problem is this line:

Code: Select all

If FindString(t$,"Contenu de la cl")
for german it is:

Code: Select all

If FindString(t$,"sselinhalt")
you have to change it for your language
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: My Wifi Keys

Post by BarryG »

Change it to what? I don't know what to put there.
Last edited by BarryG on Fri Sep 24, 2021 10:25 am, edited 1 time in total.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: My Wifi Keys

Post by Marc56us »

Same thing if you use command ligne version in CMD ?
C:\> netsh wlan show profile name=<SSID WiFi> key=clear
replace <SSID WiFi> with your SSID

PS. For PB Windows english version:

Code: Select all

If FindString(t$,"Key Content")    ;     "Contenu de la cl")
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: My Wifi Keys

Post by Cyllceaux »

oh... and this line

Code: Select all

param$="wlan show profile name="+ssid$+" key=clear"
to

Code: Select all

param$=~"wlan show profile name=\""+Trim(ssid$)+~"\" key=clear"
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: My Wifi Keys

Post by BarryG »

This is how I finally got it to work with my SSID. Don't forget SSIDs can have spaces, so you may need to wrap it in quotes.

Code: Select all

NewList ssid.s()

; Catch SSID
param$ = "wlan show profiles"
p=RunProgram("netsh",param$,"",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)

If p
  
  While ProgramRunning(p)
    If AvailableProgramOutput(p)
      t$ = ReadProgramString(p)
      n1=FindString(t$,":")
      If n1
        n2=Len(t$)
        r$=Mid(t$,n1+1,n2-n1)
        AddElement (ssid())
        ssid() = r$
      EndIf
    EndIf
    err$ = ReadProgramError(p)
    If err$
      o$+"<ERR> " + err$ +#CRLF$
    EndIf
  Wend
  
  CloseProgram(p)
  
  ;Debug r$
EndIf


If ListSize (ssid()) = 0
  MessageRequester("Erreur","No wifi Key on this computer"+Chr(10)+"This program will stop",0)
  End
EndIf

If OpenWindow(0, 0, 0, 360, 60, "LDV MULTIMEDIA MY WIFIKEYS", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  GO = 0
  ComboBoxGadget(1,1,1,358,30)
  ForEach ssid()
    AddGadgetItem(1, -1, ssid() )
  Next
  RemoveGadgetItem(1,0)
  
  SetGadgetState(1,0)
  StringGadget(2,1,32,358,30,"",#PB_String3D_ReadOnly)
  
  
  Repeat
    Event = WaitWindowEvent()
    
    
    Select EventGadget()
      Case 1
        
        If EventType() = #PB_EventType_Change
          ssid$ = GetGadgetText(1)
          param$="wlan show profile name="+Chr(34)+Trim(ssid$)+Chr(34)+" key=clear"
          p2=RunProgram("netsh",param$,"",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)
          
          If p2
            
            While ProgramRunning(p2)
              If AvailableProgramOutput(p2)
                t$ + ReadProgramString(p2)+#CRLF$
              EndIf
            Wend
            If FindString(t$,ssid$)
              n1=FindString(t$,"key content",1,#PB_String_NoCase) ; For English Windows. Other languages miss out?
              If n1
                n2=FindString(t$,":",n1)
                If n2
                  key$=Trim(Mid(t$,n2+1))
                  cr=FindString(key$,#CR$)
                  If cr
                    key$=Left(key$,cr-1)
                  EndIf
                EndIf
              EndIf
            EndIf
            
            CloseProgram(p2)
            
          Else
            Debug "erreur"
          EndIf
          SetGadgetText(2,"Wifi key: "+ key$)
          SetClipboardText(key$)
        EndIf
        
    EndSelect
  Until Event = #PB_Event_CloseWindow
EndIf
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 340
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Re: My Wifi Keys (fr-uk-de compatible)

Post by ar-s »

Thanks for your feedback.

I have update the first code.
It should be working on french/english/german windows for now.
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: My Wifi Keys (fr-uk-de compatible)

Post by ChrisR »

It works here but I have a problem with accents éèà..., OEM characters
On cmd commands, Fryquez's solution works perfectly to convert OEM characters to Unicode, See Windows console with UNICODE

The latest cmd commands created by windows seem to support English as parameter like: Dism.exe /English
Too bad this switch is not implemented on the other cmd
Post Reply