Sign in to follow this  
Followers 0
realkiller

ldap request computers

9 posts in this topic




#2 ·  Posted (edited)

@Realkiller

Why LDAP is you can keep it simple :

_NetView()

Func _NetView()
$Domain = "DOMAIN"
$Info = Run(@ComSpec & " /c net view /domain:" & $Domain , "", @SW_HIDE,2)
    
While 1
    $line = StdoutRead($Info,71)
    If @error Then ExitLoop

    ConsoleWrite($line)

Wend

    While 1
        $line = StderrRead($Info)
        If @error Then ExitLoop
        ConsoleWrite( "STDERR read: "& $line& @CR)
    Wend
EndFunc

Enjoy!!

ptrex

Edited by ptrex

Share this post


Link to post
Share on other sites

@Realkiller

Maybe you can use this ?

#include <GUIConstants.au3>
#include <iptoname.au3>
#Include <GuiListView.au3>
Global $what
$ipspl = stringsplit(@ipaddress1,".")
$pre = $ipspl[1] & "." & $ipspl[2] & "." & $ipspl[3]
GUICreate("Lan Scan",250,240)
$list = GUICtrlCreateListView("IP                           |Name                          ",5,5,240)
$scan = GUICtrlCreateButton("Scan",5,160,50)
$now = GUICtrlCreateLabel("",75,165,100,20)
GUICtrlCreateLabel("Time out:",170,165)
$timeout = GUICtrlCreateInput("250",215,162,30)
$def = GUICtrlCreateRadio("Use " & $pre & ".X",15,190)
GUICtrlSetState(-1,$GUI_CHECKED)
$set = GUICtrlCreateRadio("Set range:",15,210)
$setfrom = GUICtrlCreateInput("0.0.0",115,210,125)
GUISetState()

do
    $msg = GUIGetMsg()
    if $msg = $scan then
        _scan()
    endif
until $msg = $GUI_EVENT_CLOSE

Func _scan()
    _GUICtrlListViewDeleteAllItems($list)
    $ipspl = stringsplit(@ipaddress1,".")
    $pre = $ipspl[1] & "." & $ipspl[2] & "." & $ipspl[3]
    GUICtrlSetData($scan,"Stop")
    $timeout = GUICtrlRead($timeout)
    if guictrlread($def) & guictrlread($set) = 41 then
        $from = guictrlread($setfrom)
        $splfrom = stringsplit($from,".")
        if $splfrom[0] <> 3 OR $splfrom[1] > 255 OR $splfrom[2] > 255 OR $splfrom[3] > 255 then
            MsgBox(16,"ERROR",'Invalid "set range" input!')
            return
        endif
        $pre = $from
    endif
    for $x = 0 to 255
        $ip = $pre & "." & $x
        $ping = ping($ip,$timeout)
        If $ping then
            $ipname = _IpToName($ip)
            GUICtrlCreateListViewItem($ip & "|" & $ipname,$list)
        endif
        GUICtrlSetData($now,"Scan: " & $ip)
        $msg = GUIGetMsg()
        If $x = 255 then $msg = $scan
        If $msg = $scan then
            GUICtrlSetData($scan,"Scan")
            GUICtrlSetData($now,"Done!")
            return
        endif
    next
endfunc

regards

ptrex

Share this post


Link to post
Share on other sites

thx for replying ptrex:), that is not what im looking for if must give me online and ofline computers. the only way i can think of is a LDAP request like in Gafrost post(see above for url)

I would suggest to maintain a list of all computers and compare it with the ones "online". How else would a network know about a disconnected ( = offline) computer?

Share this post


Link to post
Share on other sites

I would suggest to maintain a list of all computers and compare it with the ones "online". How else would a network know about a disconnected ( = offline) computer?

He is on a domain. Computers are stored in Active Directory, regardless of being online.

Share this post


Link to post
Share on other sites

oke i found out the working code

#NoTrayIcon
#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <Inet.au3>
#include <Constants.au3>

Global Const $Cursor_ARROW = 2
Global Const $wbemFlagReturnImmediately = 0x10
Global Const $wbemFlagForwardOnly = 0x20
opt('MustDeclareVars', 1)
opt("GUIResizeMode", 1)

_Main()

Func _Main()
    #region **** variable declares *****
    Local $s_Machine, $t_input = "", $num_pcs = 0, $item_num = 0
    Local $Title = "LDAP", $MAIN_WINDOW
    Local $Domain, $filter, $filters, $win_state, $Retrieve_Method
    Local $exititem
    Local $Domainitem, $Filtermenu, $Filteritem, $PingTimeOutitem, $FilterIPitem
    Local $ib_search, $Btn_Search, $Btn_Exit, $i_TimeOut
    Local $lv_pcs, $lv_pcs_contextmenu, $lv_pcs_contextRefresh, $lv_pcs_contextPopulate
    Local $lv_pcs_pslist_taskmodetree, $lv_pcs_pslist_taskmode, $lv_pcs_pslist
    Local $tabs, $tab_pids, $tab_hotfixes
    Local $lv_allsoftware, $lv_allsoftware_contextmenu, $lv_allsoftware_contextRefresh
    Local $lv_pid, $lv_pid_contextmenu, $lv_pid_contextKill, $lv_pid_contextRefresh
    Local $Status, $dll, $msg, $MOUSE_POS, $explore_with, $eb_system
    Local $tab_loggedin, $lv_loggedin, $tab_drives, $lv_drives, $lv_drives_contextmenu, $lv_drives_contextExplore
    Local $tab_services, $lv_services, $lv_services_contextmenu, $lv_service_stop, $lv_service_contextRefresh, $lv_service_start
    Local $lv_service_pause, $lv_service_resume, $lv_service_delete
    Local $lv_service_startmode, $lv_service_startmodeBoot, $lv_service_startmodeSystem, $lv_service_startmodeAutomatic
    Local $lv_service_startmodeManual, $lv_service_startmodeDisabled
    Local $configmenuRetrieveMethods, $ldapitem, $netvitem, $IP_Range = "", $Use_IPRange
    #endregion **** end variable declares *****
    
    TCPStartup()
    
    #region *** read ini information ****
    $Domain = IniRead(@ScriptDir & '\AdminTool.ini', "domain", "name", "your-domain")
    $filter = IniRead(@ScriptDir & '\AdminTool.ini', "Workstations", "filter", "*")
    $Retrieve_Method = StringUpper(IniRead(@ScriptDir & '\AdminTool.ini', "RetrievePcs", "Method", "LDAP"))
    $explore_with = IniRead(@ScriptDir & '\AdminTool.ini', "Drive", "Explore", "iexplore")
    $i_TimeOut = Int(IniRead(@ScriptDir & '\AdminTool.ini', "Ping", "TimeOut", 4))
    $filters = StringSplit($filter, "|")
    
    $MAIN_WINDOW = GUICreate($Title, 280, 560, -1, -1, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU))

    $lv_pcs = GUICtrlCreateListView("Machine|IP Address|ID", 0, 0, 276, 460, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER))
    GUICtrlSendMsg($lv_pcs, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
    _GUICtrlListViewSetColumnWidth ($lv_pcs, 0, 100)
    _GUICtrlListViewSetColumnWidth ($lv_pcs, 1, 120)
    _GUICtrlListViewHideColumn ($lv_pcs, 2)
    $lv_pcs_contextmenu = GUICtrlCreateContextMenu($lv_pcs)


    GUISetState()
    
    If StringInStr($Domain, "YOUR-DOMAIN") Then _ConfigDomain($Domain, $MAIN_WINDOW)
    
    If Not StringInStr($Domain, "YOUR-DOMAIN") Then
        If $Retrieve_Method = "LDAP" Then
            _RetrieveComputersLdap($lv_pcs, $Domain, $filters, $Status, $i_TimeOut, _
                     $lv_allsoftware, $lv_pid, $lv_drives, $lv_loggedin, $eb_system, $IP_Range)
        Else
            EndIf
    EndIf
    
    GUICtrlSetState($ib_search, $GUI_FOCUS)
    
    $dll = DllOpen("user32.dll")
    
    While 1
        $msg = GUIGetMsg()
        
        $win_state = WinGetState($MAIN_WINDOW)
        
        
        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $exititem
                ExitLoop
                
            Case $msg = $Domainitem
                _ConfigDomain($Domain, $MAIN_WINDOW)
                
            Case $msg = $Filteritem
                _ConfigFilters($filter, $MAIN_WINDOW)
                
            Case $msg = $FilterIPitem
                _ConfigIpRange($IP_Range, $Use_IPRange, $MAIN_WINDOW)
                
            Case $msg = $ldapitem
                If BitAND(GUICtrlRead($ldapitem), $GUI_CHECKED) Then
                    $Retrieve_Method = "LDAP"
                    GUICtrlSetState($netvitem, $GUI_UNCHECKED)
                EndIf
                IniWrite(@ScriptDir & '\AdminTool.ini', "RetrievePcs", "Method", $Retrieve_Method)
                
                
            Case $msg = $PingTimeOutitem
                _ConfigPingTimeOut($i_TimeOut, $MAIN_WINDOW)
                

        EndSelect
    WEnd
    DllClose($dll)
    #endregion --- Show gui and process events End ---
EndFunc   ;==>_Main

#region --- Helper functions ---
  ;==>_LocateMachine





Func _RetrieveComputersLdap(ByRef $h_listview, ByRef $Domain, ByRef $filters, ByRef $pc_status, ByRef $ping_timeout, _
ByRef $lv_allsoftware, ByRef $lv_pid, ByRef $lv_drives, ByRef $lv_loggedin, ByRef $eb_system, $IP_Range = "")
    Local $lv_item, $num_pcs = 1, $inFilter
    _LockAndWait()
    GUICtrlSetData($eb_system, "")
    _GUICtrlListViewDeleteAllItems ($lv_allsoftware)
    _GUICtrlListViewDeleteAllItems ($lv_pid)
    _GUICtrlListViewDeleteAllItems ($lv_drives)
    _GUICtrlListViewDeleteAllItems ($lv_loggedin)
    _GUICtrlListViewDeleteAllItems ($h_listview)
    _GUICtrlListViewDeleteAllItems ($h_listview)
    _ResetLockWait()
    _GUICtrlListViewSetColumnWidth ($h_listview, 1, 140)
    _GUICtrlListViewHideColumn ($h_listview, 2)
    
    Local $ObjDomain = ObjGet("WinNT://" & $Domain)
    Local $ip_address, $pc_name
    For $Object In $ObjDomain
        $ip_address = ""
        If $Object.class = "Computer" Then
            $pc_name = $Object.Name
            $inFilter = 0
            If $filters[0] = 1 And $filters[1] = "*" Then
                $inFilter = 1
            Else
                For $x = 1 To $filters[0]
                    If StringUpper(StringMid($pc_name, 1, StringLen($filters[$x]))) = StringUpper($filters[$x]) Then
                        $inFilter = 1
                        ExitLoop
                    EndIf
                Next
            EndIf
            
            If $inFilter Then
                If IsArray($IP_Range) Then
                    For $x = 1 To $IP_Range[0]
                        Local $strIP = StringSplit(TCPNameToIP($pc_name), ".")
                        Local $low_r = StringSplit($IP_Range[$x], "-")
                        Local $high_r = $low_r[2]
                        $low_r = StringSplit($low_r[1], ".")
                        If (Int($strIP[1]) = Int($low_r[1]) And Int($strIP[2]) = Int($low_r[2]) And Int($strIP[3]) = Int($low_r[3])) And _
                                (Int($strIP[4]) >= Int($low_r[4]) And Int($strIP[4]) <= Int($high_r)) Then
                            $lv_item = GUICtrlCreateListViewItem($pc_name & "| | ", $h_listview)
                            GUICtrlSetData($lv_item, $pc_name & "| |" & $lv_item)
                            _SetStatus($h_listview, _GUICtrlListViewGetItemCount ($h_listview) - 1, $pc_status, $ping_timeout)
                            _ReduceMemory()
                            GUICtrlSetData($pc_status, "Machines: " & $num_pcs)
                            $num_pcs += 1
                            ExitLoop
                        EndIf
                    Next
                Else
                    $lv_item = GUICtrlCreateListViewItem($pc_name & "| | ", $h_listview)
                    GUICtrlSetData($lv_item, $pc_name & "| |" & $lv_item)
                    _SetStatus($h_listview, _GUICtrlListViewGetItemCount ($h_listview) - 1, $pc_status, $ping_timeout)
                    _ReduceMemory()
                    GUICtrlSetData($pc_status, "Machines: " & $num_pcs)
                    $num_pcs += 1
                EndIf
            EndIf
        EndIf
    Next
    _GUICtrlListViewSetColumnWidth ($h_listview, 0, 140)
    _GUICtrlListViewSetColumnWidth ($h_listview, 1, 100)
    _GUICtrlListViewHideColumn ($h_listview, 2)
    GUISetCursor($Cursor_ARROW, 1)
EndFunc   ;==>_RetrieveComputersLdap

Func _SetStatus(ByRef $lv_listview, $index, ByRef $Status, ByRef $ping_length)
    Local $pc_name = _GUICtrlListViewGetItemText ($lv_listview, $index, 0)
    Local $ip_address = '', $ping_time
    If $ping_length Then
        $ping_time = Ping($pc_name, $ping_length)
        If $ping_time Then
            Local $lv_item = _GUICtrlListViewGetItemText ($lv_listview, $index, 2)
            $ip_address = TCPNameToIP($pc_name)
            GUICtrlSetData($lv_item, $pc_name & "|" & $ip_address & "|" & $lv_item)
            GUICtrlSetImage($lv_item, @ScriptDir & "\OnLine.ico")
            _ReduceMemory()
            Return 1
        Else
            Local $lv_item = _GUICtrlListViewGetItemText ($lv_listview, $index, 2)
            If Ping($lv_item,100) Then
                GUICtrlSetImage($lv_item, @ScriptDir & "\OnLine.ico")
                Else
            GUICtrlSetImage($lv_item, @ScriptDir & "\OffLine.ico")
            EndIf
        EndIf
    Else
        Local $lv_item = _GUICtrlListViewGetItemText ($lv_listview, $index, 2)
        $ip_address = TCPNameToIP($pc_name)
        If $ip_address = "" Then $ip_address = " "
        GUICtrlSetData($lv_item, $pc_name & "|" & $ip_address & "|" & $lv_item)
        GUICtrlSetImage($lv_item, @ScriptDir & "\OnLine.ico")
        _ReduceMemory()
        Return 1
    EndIf
    _ReduceMemory()
    Return 0
EndFunc   ;==>_SetStatus

Func _GetRole(ByRef $s_pc, ByRef $Status)
    Local $objWMIService, $colComputer, $objComputer
    $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $s_pc & "\root\cimv2")
    If @error Then
        GUICtrlSetData($Status, "Unable to retrieve Role:" & $s_pc)
        Return
    EndIf
    $colComputer = $objWMIService.ExecQuery ("Select * from Win32_ComputerSystem", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If @error Then
        GUICtrlSetData($Status, "Unable to retrieve Role:" & $s_pc)
        Return
    EndIf
    For $objComputer In $colComputer
        If Int($objComputer.DomainRole) = 1 Then
            GUICtrlSetData($Status, $s_pc & " is WorkStation")
        ElseIf Int($objComputer.DomainRole) = 3 Then
            GUICtrlSetData($Status, $s_pc & " is Server")
        ElseIf Int($objComputer.DomainRole) = 4 Then
            GUICtrlSetData($Status, $s_pc & " is Backup Domain Controller")
        ElseIf Int($objComputer.DomainRole) = 5 Then
            GUICtrlSetData($Status, $s_pc & " is Primary Domain Controller")
        Else
            GUICtrlSetData($Status, "Unable to retrieve Role:" & $s_pc)
        EndIf
        Return $objComputer.DomainRole
    Next
EndFunc   ;==>_GetRole
#region --- Config functions ---
Func _ConfigDomain(ByRef $s_Domain, ByRef $MAIN_WINDOW)
    GUISetState(@SW_DISABLE, $MAIN_WINDOW)
    Local $Save, $LABEL, $CLOSE, $domain_msg, $Domain_Window
    $Domain_Window = GUICreate("Domain Config", 300, 140, -1, -1, -1, -1, $MAIN_WINDOW)
    #Region --- CodeWizard generated code Start ---
    If Not IsDeclared('Cadet_Blue_3') Then Dim $Cadet_Blue_3 = 0x7AC5CD
    GUISetBkColor($Cadet_Blue_3)
    #EndRegion --- CodeWizard generated code End ---
    GUICtrlCreateLabel("Domain to Search", 20, 10, 120, 20)
    Local $domain_input = GUICtrlCreateInput($s_Domain, 20, 40, 250, 20)
    $Save = GUICtrlCreateButton("Save", 20, 100, 120, 25)
    $CLOSE = GUICtrlCreateButton("Close", 160, 100, 120, 25)
    GUISetState()
    Do
        $domain_msg = GUIGetMsg()
        Select
            Case $domain_msg = $Save
                $s_Domain = GUICtrlRead($domain_input)
                IniWrite(@ScriptDir & '\AdminTool.ini', "domain", "name", $s_Domain)
            Case $domain_msg = $CLOSE
                ExitLoop
        EndSelect
    Until $domain_msg = $GUI_EVENT_CLOSE
    GUIDelete($Domain_Window)
    GUISetState(@SW_ENABLE, $MAIN_WINDOW)
    GUISetState(@SW_SHOW, $MAIN_WINDOW)
EndFunc   ;==>_ConfigDomain

Func _ConfigPingTimeOut(ByRef $i_TimeOut, ByRef $MAIN_WINDOW)
    GUISetState(@SW_DISABLE, $MAIN_WINDOW)
    Local $Save, $LABEL, $CLOSE, $TimeOut_msg, $TimeOut_Window
    $TimeOut_Window = GUICreate("Ping Time Out Config", 340, 140, -1, -1, -1, -1, $MAIN_WINDOW)
    #Region --- CodeWizard generated code Start ---
    If Not IsDeclared('Cadet_Blue_3') Then Dim $Cadet_Blue_3 = 0x7AC5CD
    GUISetBkColor($Cadet_Blue_3)
    #EndRegion --- CodeWizard generated code End ---
    GUICtrlCreateLabel("Ping Time Out (Milliseconds, 0 = no ping)", 10, 10, 320, 20, $ES_CENTER)
    Local $TimeOut_input = GUICtrlCreateInput($i_TimeOut, 90, 40, 150, 20, $ES_NUMBER)
    $Save = GUICtrlCreateButton("Save", 40, 100, 120, 25)
    $CLOSE = GUICtrlCreateButton("Close", 180, 100, 120, 25)
    GUISetState()
    Do
        $TimeOut_msg = GUIGetMsg()
        Select
            Case $TimeOut_msg = $Save
                $i_TimeOut = Int(GUICtrlRead($TimeOut_input))
                IniWrite(@ScriptDir & '\AdminTool.ini', "Ping", "TimeOut", $i_TimeOut)
            Case $TimeOut_msg = $CLOSE
                ExitLoop
        EndSelect
    Until $TimeOut_msg = $GUI_EVENT_CLOSE
    GUIDelete($TimeOut_Window)
    GUISetState(@SW_ENABLE, $MAIN_WINDOW)
    GUISetState(@SW_SHOW, $MAIN_WINDOW)
EndFunc   ;==>_ConfigPingTimeOut

Func _ConfigFilters(ByRef $s_filter, ByRef $MAIN_WINDOW)
    GUISetState(@SW_DISABLE, $MAIN_WINDOW)
    Local $Save, $LABEL, $CLOSE, $filter_msg, $Filter_Window, $win_state
    Local $lv_filters, $a_filter, $x, $filter_input, $Add, $Delete
    $Filter_Window = GUICreate("Filter Config", 300, 220, -1, -1, -1, -1, $MAIN_WINDOW)
    #Region --- CodeWizard generated code Start ---
    If Not IsDeclared('Cadet_Blue_3') Then Dim $Cadet_Blue_3 = 0x7AC5CD
    GUISetBkColor($Cadet_Blue_3)
    #EndRegion --- CodeWizard generated code End ---
    GUICtrlCreateLabel('PC Name Filter', 20, 10, 250, 20)
    GUICtrlCreateLabel("All Example: *", 20, 25, 250, 20)
    GUICtrlCreateLabel("Example: Z", 20, 40, 250, 20)
    $lv_filters = GUICtrlCreateListView("Filters", 20, 70, 100, 100, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER))
    GUICtrlSendMsg($lv_filters, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
    GUICtrlSendMsg($lv_filters, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
    _GUICtrlListViewSetColumnWidth ($lv_filters, 0, 90)
    $a_filter = StringSplit($s_filter, "|")
    For $x = 1 To $a_filter[0]
        GUICtrlCreateListViewItem($a_filter[$x], $lv_filters)
    Next
    $filter_input = GUICtrlCreateInput("", 140, 70, 120, 20)
    $Add = GUICtrlCreateButton("Add", 140, 100, 120, 25)
    $Delete = GUICtrlCreateButton("Delete", 140, 130, 120, 25)
    GUICtrlSetState($Delete, $GUI_DISABLE)
    $Save = GUICtrlCreateButton("Save", 20, 190, 120, 25)
    $CLOSE = GUICtrlCreateButton("Close", 160, 190, 120, 25)
    GUISetState()
    Do
        $filter_msg = GUIGetMsg()
        Select
            Case $filter_msg = $Save
                If _GUICtrlListViewGetItemCount ($lv_filters) > 0 Then
                    $s_filter = ""
                    For $x = 0 To _GUICtrlListViewGetItemCount ($lv_filters) - 1
                        $s_filter = $s_filter & "|" & _GUICtrlListViewGetItemText ($lv_filters, $x, 0)
                    Next
                    $s_filter = StringTrimLeft($s_filter, 1)
                    IniWrite(@ScriptDir & '\AdminTool.ini', "Workstations", "filter", $s_filter)
                EndIf
            Case $filter_msg = $Delete
                _GUICtrlListViewDeleteItemsSelected ($lv_filters)
                GUICtrlSetState($Delete, $GUI_DISABLE)
            Case $filter_msg = $Add
                If StringLen(GUICtrlRead($filter_input)) Then GUICtrlCreateListViewItem(GUICtrlRead($filter_input), $lv_filters)
            Case $filter_msg = $CLOSE
                ExitLoop
            Case $filter_msg = $GUI_EVENT_PRIMARYDOWN
                $win_state = WinGetState($Filter_Window)
                If BitAND($win_state, 8) And BitAND($win_state, 2) Then
                    If _GUICtrlListViewGetCurSel ($lv_filters) <> $LV_ERR Then
                        GUICtrlSetState($Delete, $GUI_ENABLE)
                    EndIf
                EndIf
        EndSelect
    Until $filter_msg = $GUI_EVENT_CLOSE
    GUIDelete($Filter_Window)
    GUISetState(@SW_ENABLE, $MAIN_WINDOW)
    GUISetState(@SW_SHOW, $MAIN_WINDOW)
EndFunc   ;==>_ConfigFilters

Func _ConfigIpRange(ByRef $a_IPRange, ByRef $Use_IPRange, ByRef $MAIN_WINDOW)
    GUISetState(@SW_DISABLE, $MAIN_WINDOW)
    Local $Save, $LABEL, $CLOSE, $filter_msg, $Filter_Window, $win_state, $ip, $nCurEdit = 0, $ip_tmp
    Local $lv_filters, $s_filter, $x, $filter_input[5], $filter_use, $Add, $Delete, $ip_len, $current_control
    $Filter_Window = GUICreate("IP Range Config", 360, 220, -1, -1, -1, -1, $MAIN_WINDOW)
    #Region --- CodeWizard generated code Start ---
    If Not IsDeclared('Cadet_Blue_3') Then Dim $Cadet_Blue_3 = 0x7AC5CD
    GUISetBkColor($Cadet_Blue_3)
    #EndRegion --- CodeWizard generated code End ---
    GUICtrlCreateLabel('Range(s) of IP Filter', 20, 10, 250, 20)
    $lv_filters = GUICtrlCreateListView("Start|End", 20, 40, 140, 140, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER))
    GUICtrlSendMsg($lv_filters, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
    GUICtrlSendMsg($lv_filters, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
    _GUICtrlListViewSetColumnWidth ($lv_filters, 0, 90)
    If IsArray($a_IPRange) Then
        For $x = 1 To $a_IPRange[0]
            $s_filter = StringReplace($a_IPRange[$x], "-", "|")
            GUICtrlCreateListViewItem($s_filter, $lv_filters)
        Next
    EndIf
    $filter_use = GUICtrlCreateCheckbox("Use IP Range Inclusion Filter(s)", 170, 40)
    If $Use_IPRange Then GUICtrlSetState($filter_use, $GUI_CHECKED)
    
    $filter_input[0] = GUICtrlCreateInput("", 170, 70, 30, 20, $ES_NUMBER)
    GUICtrlSetLimit($filter_input[0], 3, 1)
    $filter_input[1] = GUICtrlCreateInput("", 205, 70, 30, 20, $ES_NUMBER)
    GUICtrlSetLimit($filter_input[1], 3, 1)
    $filter_input[2] = GUICtrlCreateInput("", 240, 70, 30, 20, $ES_NUMBER)
    GUICtrlSetLimit($filter_input[2], 3, 1)
    $filter_input[3] = GUICtrlCreateInput("", 275, 70, 30, 20, $ES_NUMBER)
    GUICtrlSetLimit($filter_input[3], 3, 1)
    GUICtrlCreateLabel("-", 310, 70, 10, 20)
    $filter_input[4] = GUICtrlCreateInput("", 320, 70, 30, 20, $ES_NUMBER)
    GUICtrlSetLimit($filter_input[4], 3, 1)
    $Add = GUICtrlCreateButton("Add", 170, 100, 120, 25)
    GUICtrlSetState($Add, $GUI_DISABLE)
    $Delete = GUICtrlCreateButton("Delete", 170, 130, 120, 25)
    GUICtrlSetState($Delete, $GUI_DISABLE)
    $Save = GUICtrlCreateButton("Save", 50, 190, 120, 25)
    $CLOSE = GUICtrlCreateButton("Close", 190, 190, 120, 25)
    GUISetState()
    GUICtrlSetState($filter_input[0], $GUI_FOCUS)
    Do
        $filter_msg = GUIGetMsg()
        $ip = _IsPressedMod()
        If $ip > 0 Then
            $ip_tmp = GUICtrlRead($filter_input[$nCurEdit])
            If (StringLen($ip_tmp) = 3) And not ($ip = 8) Then
                If $nCurEdit = UBound($filter_input) - 1 Then ContinueLoop
                $nCurEdit = $nCurEdit + 1
                GUICtrlSetState($filter_input[$nCurEdit], $GUI_FOCUS)
            ElseIf (StringLen($ip_tmp) = 0) and ($ip = 8) Then
                If $nCurEdit = 0 Then ContinueLoop
                $nCurEdit = $nCurEdit - 1
                Sleep ( 200 ) ; make sure buffer clears
                GUICtrlSetState($filter_input[$nCurEdit], $GUI_FOCUS)
            GUICtrlSetData($filter_input[$nCurEdit], GUICtrlRead($filter_input[$nCurEdit]))
            EndIf
        EndIf
        ; set current selection in case user hit tab key or used mouse to select input
        $current_control = ControlGetFocus($Filter_Window)
        Select
            Case $current_control = "Edit1" And $nCurEdit > 0
                $nCurEdit = 0
            Case $current_control = "Edit2" And $nCurEdit <> 1
                $nCurEdit = 1
            Case $current_control = "Edit3" And $nCurEdit <> 2
                $nCurEdit = 2
            Case $current_control = "Edit4" And $nCurEdit <> 3
                $nCurEdit = 3
            Case $current_control = "Edit5" And $nCurEdit < 4
                $nCurEdit = 4
        EndSelect

        Select
            Case $filter_msg = $Save
                If BitAND(GUICtrlRead($filter_use), $GUI_CHECKED) Then
                    $Use_IPRange = 1
                Else
                    $Use_IPRange = 0
                EndIf
                IniWrite(@ScriptDir & '\AdminTool.ini', "IP-Filter", "Use", $Use_IPRange)
                IniDelete(@ScriptDir & '\AdminTool.ini', "IP-Ranges")
                If _GUICtrlListViewGetItemCount ($lv_filters) > 0 Then
                    ReDim $a_IPRange[_GUICtrlListViewGetItemCount ($lv_filters) + 1]
                    $a_IPRange[0] = _GUICtrlListViewGetItemCount ($lv_filters)
                    For $x = 0 To _GUICtrlListViewGetItemCount ($lv_filters) - 1
                        $a_IPRange[$x + 1] = StringReplace(_GUICtrlListViewGetItemText ($lv_filters, $x), "|", "-")
                        IniWrite(@ScriptDir & '\AdminTool.ini', "IP-Ranges", "Range" & $x + 1, $a_IPRange[$x + 1])
                    Next
                Else
                    $a_IPRange = ""
                EndIf
            Case $filter_msg = $Delete
                _GUICtrlListViewDeleteItemsSelected ($lv_filters)
                GUICtrlSetState($Delete, $GUI_DISABLE)
            Case $filter_msg = $Add
                $ip = ""
                For $x = 0 To 3
                    $ip = $ip & GUICtrlRead($filter_input[$x]) & "."
                Next
                $ip = StringTrimRight($ip, 1)
                GUICtrlCreateListViewItem($ip & "|" & GUICtrlRead($filter_input[4]), $lv_filters)
                For $x = 0 To 4
                    GUICtrlSetData($filter_input[$x], "")
                Next
                ;***********************************
                $nCurEdit = 0
                ;***********************************
            Case $filter_msg = $CLOSE
                ExitLoop
            Case $filter_msg = $GUI_EVENT_PRIMARYDOWN
                $win_state = WinGetState($Filter_Window)
                If BitAND($win_state, 8) And BitAND($win_state, 2) Then
                    If _GUICtrlListViewGetCurSel ($lv_filters) <> $LV_ERR Then
                        GUICtrlSetState($Delete, $GUI_ENABLE)
                    EndIf
                EndIf
        EndSelect
        $ip_len = True
        For $x = 0 To 4
            If StringLen(GUICtrlRead($filter_input[$x])) == 0 Then
                $ip_len = False
                If ControlCommand($Filter_Window, "", $Add, "IsEnabled", "") Then GUICtrlSetState($Add, $GUI_DISABLE)
                ExitLoop
            EndIf
        Next
        If $ip_len And Not ControlCommand($Filter_Window, "", $Add, "IsEnabled", "") Then GUICtrlSetState($Add, $GUI_ENABLE)
    Until $filter_msg = $GUI_EVENT_CLOSE
    GUIDelete($Filter_Window)
    GUISetState(@SW_ENABLE, $MAIN_WINDOW)
    GUISetState(@SW_SHOW, $MAIN_WINDOW)
EndFunc   ;==>_ConfigIpRange
#endregion --- Config functions End ---

Func _IsPressedMod()
    Local $aR, $bRv, $hexKey, $i
    For $i = 8 To 128
        $hexKey = '0x' & Hex($i, 2)
        $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
        If $aR[0] <> 0 Then Return $i
    Next
    Return 0
EndFunc   ;==>_IsPressedMod

Func _GetIPRanges($IniFile, ByRef $IP_Range)
    Local $Ranges = IniReadSection($IniFile, "IP-Ranges"), $x
    If Not @error Then
        Dim $IP_Range[$Ranges[0][0] + 1]
        $IP_Range[0] = $Ranges[0][0]
        For $x = 1 To $Ranges[0][0]
            $IP_Range[$x] = $Ranges[$x][1]
        Next
    EndIf
EndFunc   ;==>_GetIPRanges

Func _ReduceMemory()
    Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory

Func _LockAndWait()
    GUISetState(@SW_LOCK)
    
EndFunc   ;==>_LockAndWait

Func _ResetLockWait()
    GUISetState(@SW_UNLOCK)
    GUISetCursor($Cursor_ARROW, 1)
    _ReduceMemory()
EndFunc   ;==>_ResetLockWait
#endregion --- Helper functions End ---

#region --- About ---

Share this post


Link to post
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
Sign in to follow this  
Followers 0