Jump to content

wireless connection info [need help to complite it]


ElCamino
 Share

Recommended Posts

been reading and learning for some time, heres what i'm working on, and would love to get some feedback and help to clean this code, also to complete the functions left. thats why i post this in the help section, please be nice with this noob.

;==================================================================================================================
;
;wifi manager, by El Camino ver. 0.1 alpha
;wiriten for RoadRunner Use, not complete yet.
;original thread below
;http://www.mp3car.com/vbulletin/rr-plugins/107929-wifi-connection-labels.html
;==================================================================================================================

$wifi_man = "alpha 0.1"
If WinExists($wifi_man) Then Exit 
AutoItWinSetTitle($wifi_man)


;for testing the key "esc" is set as a hotkey, to stop this process.
 HotKeySet ("{esc}", "_exit")
 
dim $ssid, $signal, $mode, $signal_db, $speed, $power, $channel, $weps, $rts, $frag

;the wireless adapter's name.
 $wifiAdapter=IniRead(@scriptdir&'\wifi_man.ini', 'SETTINGS', 'adapter', '')
 
 ;the sleep time during scan.
 $pause=IniRead(@scriptdir&'\wifi_man.ini', 'SETTINGS', 'pause', '5000')
 
;While 1
 _ssid()
 _signal()
 _type()
 _signal_db()
 _speed()
 _channel()
 _weps()
 _frag()
 _rts()
 _power()
 ;Sleep($pause)

ConsoleWrite ("network : "&$ssid&@CRLF _
&"signal  : "&$signal&@CRLF _
&"Type    : "&$mode&@CRLF _
&"signaldb: "&$signal_db&@CRLF _
&"speed   : "&$speed&@CRLF _
&"Weap    : "&$weps&@CRLF _
&"channel : "&$channel&@CRLF _
&"rts     : "&$rts&@CRLF _
&"frag    : "&$frag&@CRLF _
&"power   : "&$power&@CRLF)

;WEnd


;=======================================================================================================
;returns the network name, $ssid var
;=======================================================================================================
Func _ssid()
    $strComputer = "." 
    $objSWbemServices = ObjGet("winmgmts:\\"& $strComputer & "\root\wmi") 
    $ssid = ""
 $colInstances = $objSWbemServices.ExecQuery _
  ("SELECT * FROM MSNdis_80211_ServiceSetIdentifier WHERE InstanceName ='" & $wifiAdapter & "'")
For $objInstance in $colInstances
    For $decval in $objInstance.Ndis80211SsId
        if ($decval > 31 AND $decval < 127) then
            $ssid = $ssid & Chr($decval)
        EndIf
    next
next
 if StringLen($ssid) = 0 Then
    $ssid = "Not Connected"
    EndIf
EndFunc ;==>_ssid

 ;======================================================================================================
;returns the signal strength type, $aignal var
 ;======================================================================================================
 Func _signal()
     $signal = ""
$strComputer = "."
 $objWMI = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi")
 $colItems = $objWMI.InstancesOf("MSNdis_80211_ReceivedSignalStrength WHERE InstanceName ='" & $wifiAdapter & "'")
For $objItem in $colItems
  $intStrength = $objItem.NDIS80211ReceivedSignalStrength
    If $intStrength > -57 Then
    $signal = "Excellent"
    ElseIf $intStrength > -68 Then
       $signal = "Very Good"
   ElseIf $intStrength > -72 Then
        $signal = "Good"
   ElseIf $intStrength > -80 Then
       $signal = "Low"
  ElseIf $intStrength > -90 Then
     $signal = "Very Low"
     EndIf
 next
 
 if StringLen($signal) = 0 then
   $signal = "Not determined"
EndIf
EndFunc;==>_signal

;=======================================================================================================
;returns the network type $mode var
;=======================================================================================================
Func _type()    
    $strComputer = "." 
    $objSWbemServices = ObjGet("winmgmts:\\"& $strComputer & "\root\wmi") 
 $colInstances = $objSWbemServices.ExecQuery _
  ("SELECT * FROM MSNdis_80211_NetworkTypeInUse WHERE InstanceName ='" & $wifiAdapter & "'")
For $objInstance in $colInstances
    $raw_mode = $objInstance.Ndis80211NetworkTypeInUse.Ndis80211NetworkType 
    if $raw_mode=0 then
        $mode="Ad-Hoc"
    ElseIf $raw_mode=3 then
        $mode="Infrastructure"
    EndIf
next
 if StringLen($mode) = 0 then
   $mode = "Not determined"
EndIf
EndFunc;==>_type

;======================================================================================================= 
;retunrs channel used, $channel var
;=======================================================================================================

Func _channel ()
    dim $channels, $channel
     $wifiAdapter="BUFFALO WLI-CB-G54HP Wireless LAN Adapter"
$channels = _ArrayCreate(2412000,2417000,2422000,2427000,2432000,2437000,2442000,2447000,2452000,2457000,2462000)
    $strComputer = "." 
    $objSWbemServices = ObjGet("winmgmts:\\"& $strComputer & "\root\wmi") 
 $colInstances = $objSWbemServices.ExecQuery _
  ("SELECT * FROM MSNdis_80211_Configuration WHERE InstanceName ='" & $wifiAdapter & "'")
For $objInstance in $colInstances
    $raw_channel = $objInstance.Ndis80211Config.DSConfig
$channel = ""
For $c = 0 to UBound($channels,1) -1
   if $raw_channel = $channels[$c] then
       $channel = $c + 1
   EndIf
   Next
   next
    if StringLen($Channel) = 0 then
   $Channel = "Not determined"
EndIf
EndFunc   ;==>_channel

;=========================================================================================================================
;
; Function Name:    _ArrayCreate()
; Description:      Create a small array and quickly assign values.
; Parameter(s):     $v_0  - The first element of the array.
;                   $v_1  - The second element of the array (optional).
;                   ...
;                   $v_20 - The twentyfirst element of the array (optional).
; Requirement(s):   None.
; Return Value(s):  The array with values.
; Author(s):        Dale (Klaatu) Thompson, rewritten JdeB to avoid Eval() errors in Obsufcator
; Note(s):          None.
;
;========================================================================================================================
Func _ArrayCreate($v_0, $v_1 = 0, $v_2 = 0, $v_3 = 0, $v_4 = 0, $v_5 = 0, $v_6 = 0, $v_7 = 0, $v_8 = 0, $v_9 = 0, $v_10 = 0, $v_11 = 0, $v_12 = 0, $v_13 = 0, $v_14 = 0, $v_15 = 0, $v_16 = 0, $v_17 = 0, $v_18 = 0, $v_19 = 0, $v_20 = 0)
    Local $av_Array[21] = [$v_0, $v_1, $v_2, $v_3, $v_4, $v_5, $v_6, $v_7, $v_8, $v_9, $v_10, $v_11, $v_12, $v_13, $v_14, $v_15, $v_16, $v_17, $v_18, $v_19, $v_20]
    ReDim $av_Array[@NumParams]
    Return $av_Array
    ; Create fake usage for the variables to suppress Au3Check -w 6
EndFunc   ;==>_ArrayCreate

;=======================================================================================================================
; returns link speed $speed var
;=======================================================================================================================

Func _speed()
    $strComputer = "." 
    $objSWbemServices = ObjGet("winmgmts:\\"& $strComputer & "\root\wmi") 
 $colInstances = $objSWbemServices.ExecQuery _
  ("SELECT * FROM MSNdis_LinkSpeed WHERE Active = True AND InstanceName ='" & $wifiAdapter & "'")
For $objInstance in $colInstances
    $speed = $objInstance.NdisLinkSpeed / 10000&" Mbps"
next
 if StringLen($speed) = 0 then
   $speed = "Not determined"
EndIf
EndFunc    ;==>_speed

;=======================================================================================================
;returns rts threshold $rts var
;=======================================================================================================
Func _rts()
    $strComputer = "." 
    $objSWbemServices = ObjGet("winmgmts:\\"& $strComputer & "\root\wmi") 
 $colInstances = $objSWbemServices.ExecQuery _
  ("SELECT * FROM MSNdis_80211_RTSThreshold WHERE InstanceName ='" & $wifiAdapter & "'")
For $objInstance in $colInstances
    $rts = $objInstance.Ndis80211RTSThreshold
next
 if StringLen($rts) = 0 then
   $rts = "Not determined"
EndIf
EndFunc  ;==>_rts

;=======================================================================================================
;returns fragmentation threshold $frag var
;=======================================================================================================
Func _frag()
    $strComputer = "." 
    $objSWbemServices = ObjGet("winmgmts:\\"& $strComputer & "\root\wmi") 
 $colInstances = $objSWbemServices.ExecQuery _
  ("SELECT * FROM MSNdis_80211_FragmentationThreshold WHERE InstanceName ='" & $wifiAdapter & "'")
For $objInstance in $colInstances
    $frag = $objInstance.Ndis80211FragmentationThreshold
next
 if StringLen($frag) = 0 then
   $frag = "Not determined"
   EndIf
EndFunc    ;==>_frag

;=======================================================================================================
;returns power mode, $power var
;=======================================================================================================
 
 Func _power()
     dim $power
        $strComputer = "." 
    $objSWbemServices = ObjGet("winmgmts:\\"& $strComputer & "\root\wmi") 
 $colInstances = $objSWbemServices.ExecQuery _
  ("SELECT * FROM MSNdis_80211_PowerMode WHERE InstanceName ='" & $wifiAdapter & "'")
For $objInstance in $colInstances
    $power_raw = $objInstance.Ndis80211PowerMode
    if $power_raw=0 then
        $power="Cam"
    Elseif $power_raw=1 then
        $power="Max PSP"
            Elseif $power_raw=2 then
        $power="Fast PSP"
    EndIf
next
 if StringLen($power) = 0 then
   $power = "Not determined"
EndIf
EndFunc   ;==>_power

;========================================================================================================
;returns received $signal in db $signal_db var
;========================================================================================================

Func _signal_db()
    dim $signal_db
        $strComputer = "." 
    $objSWbemServices = ObjGet("winmgmts:\\"& $strComputer & "\root\wmi") 
 $colInstances = $objSWbemServices.ExecQuery _
  ("SELECT * FROM MSNdis_80211_ReceivedSignalStrength WHERE InstanceName ='" & $wifiAdapter & "'")
For $objInstance in $colInstances
            $sigraw = StringTrimLeft($objInstance.Ndis80211ReceivedSignalStrength, 1)
            $signal_db = $sigraw & " dB"
        next
         if StringLen($signal_db) = 0 then
   $signal_db = "Not determined"
EndIf
    EndFunc   ;==>_signal_db
    
;=========================================================================================================
;returns wep status $weps var
;=========================================================================================================

Func _weps()
    $strComputer = "."
$objWMI = ObjGet("winmgmts://" & $strComputer & "/root\WMI")
$objInstances = $objWMI.InstancesOf("MSNdis_80211_WEPStatus WHERE InstanceName ='" & $wifiAdapter & "'")

For $objInstance in $objInstances
     $status=$objInstance.Ndis80211WEPStatus
     if $status=0 Then
         $weps="Enabled"
     ElseIf $status=1 Then
         $weps="Disabled"
     ElseIf $status=2 Then
         $weps="Key Absent"
     ElseIf $status=3 Then
         $weps="Not Supported"
         EndIf
     Next
      if StringLen($weps) = 0 then
   $weps = "Not determined"
EndIf
    EndFunc ;==>_weps
    
;================================================================================================================
;just for exiting, while testing. . .
;================================================================================================================
Func _exit()
    Exit
    EndFunc   ;==>_exit
Edited by ElCamino
Link to comment
Share on other sites

To fear1313's point this looks..... interesting. A couple of questions for you though, why do you say this is written for RoadRunner? Most of what I saw applies to your wifi adapter and that's pretty independent of your broadband connection. Also I'm going to guess you found these snippets on the web others put together since you use different variable names across the functions. Or is there a reason for this? Where did you get the values to determine what the wmi output means? For example on _weps() where did you get

For $objInstance in $objInstances
     $status=$objInstance.Ndis80211WEPStatus
     if $status=0 Then
         $weps="Enabled"
     ElseIf $status=1 Then
         $weps="Disabled"
     ElseIf $status=2 Then
         $weps="Key Absent"
     ElseIf $status=3 Then
         $weps="Not Supported"
     EndIf
Next
if StringLen($weps) = 0 then
    $weps = "Not determined"
EndIf

I think if you tweak the minor stuff including the logic pointed out in the above example, this could be pretty cool. There's other stuff, but you did ask that we be gentle, right? :)

@fear1313 - what do you mean by WEP connections? You want the number of wifi connections available that's provided by MSNdis_80211_BSSIList or were you thinking of something else? Besides, without the key and index what good would other WEP connections be to you? Yes, yes I know its flawed security but its not wide open for easy instant access. Maybe you can share the class and share your ideas with us?

Link to comment
Share on other sites

@fear1313 - what do you mean by WEP connections? You want the number of wifi connections available that's provided by MSNdis_80211_BSSIList or were you thinking of something else? Besides, without the key and index what good would other WEP connections be to you? Yes, yes I know its flawed security but its not wide open for easy instant access. Maybe you can share the class and share your ideas with us?

I meant to say if the connection was WEP enabled. Typo =] Know it's useless but it just kind of seems like it belongs up there.

[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Link to comment
Share on other sites

@ElCamino

I see that you got inspired by my example.

WiFi SSID

That's good !!

But non of the functions are returning any values when connected ?

Best is to review my example and check whare it went wrong.

Did you have values returning on your connetion ?

regards

ptrex

Link to comment
Share on other sites

@fear1313 - that's what his _weps() is trying to do, as I mentioned his logic isn't quite right just yet :). But yes if 0 = WEP, 4 = WPA-PSK, etc :).

.... But non of the functions are returning any values when connected ?

Thanks for the heads up ptrex! I didn't know you'd done parts of this one too. I'll be adding that to my list of code to study, you know if its from ptrex its worth having and studying!! If you change the following to = your wifi card then it'll work.... well the functions that have the correct logic will work :P

$wifiAdapter=IniRead(@scriptdir&'\wifi_man.ini', 'SETTINGS', 'adapter', '')
Edited by ssubirias3
Link to comment
Share on other sites

thanks for looking, the "not determind" value was needed for my specific needs, thats why i put that, this was written for "RoadRunner", this program is a frontend design to control an incarpc, so this script was made with that in mind, i needed to have some labels to see the connection's info if established, autoit pass the values to this program and dispalys them.

http://www.scriptinternals.de/new/us/default.asp?WMI_MSNdis_80211_BSSIList

@ptrex

dont get me wrong but i found a vb script googling sometime back, and is the one that pulls the "ssid" and got the idea from it, took it ported to autoit, and from there made the other functions, true that they are so similar, that i was affraid to post this.

take a look at my other threat in my other forum. you can see that all works very well the way i have it. just need to finish it.once again ptrex my respects to you.

http://www.mp3car.com/vbulletin/rr-plugins...ion-labels.html

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...