Jump to content

Information about computers on a Network


 Share

Recommended Posts

Hello guys,
I analyzed script that you find below and I planned to add more information to the ListView, type:

- Username login
- Now the computer power

You think you can take this information and show them in the table?

#include <Array.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
Dim $aBrowdcast[4]
$aBrowdcast[0]=@IPAddress1
$aBrowdcast[1]=@IPAddress2
$aBrowdcast[2]=@IPAddress3
$aBrowdcast[3]=@IPAddress4
$filemaclist="MACLIST.DAT"

Dim $MACAddressList[1]
$MACAddressList[0] = "08000e42faa7"

; ===================================================================
; Gui
;   
; ===================================================================
$mainwindow=GUICreate("WOLLE",450,300)
$mwbtnExit=GUICtrlCreateButton("Exit",350,150,100)
$mwbtnGetMac=GUICtrlCreateButton("Get Mac adresses",10,150,100)
$mwbtnWakeupall=GUICtrlCreateButton("Wake up all in list",130,150,100)
$mwbtnWakeupSelected=GUICtrlCreateButton("Wake up selected",240,150,100)
$mwlblIpRange=GUICtrlCreateLabel("Enter Start and End IP for search, will only search for last segment, sorry....",10,115,200,30)

$mvinpIpStart=GUICtrlCreateInput("192.168.0.1",250,120,100,15)
$mvinpIpStop=GUICtrlCreateInput("192.168.0.10",350,120,100,15)
$mvinpWakeupTimeHH=GUICtrlCreateCombo("0",10,220,40)
$mvinpWakeupTimeMM=GUICtrlCreateCombo("00",50,220,40)
$mvinpWakeupTimeSS=GUICtrlCreateCombo("00",90,220,40)
FillTimeCombos()
$mwbtnActivateTimer=GUICtrlCreateButton("Activate Timer",290,220,120)
$mwbtnSetTimertoNow=GUICtrlCreateButton("Set Timer to now",160,220,120)
$mwbtnReadMacListFile=GUICtrlCreateButton("MACLIST.DAT",260,50,120)
$mwlvMacadresses=GUICtrlCreateListView("MacAdresses   |IP                ",10,10,250,100)
$mwlblStatus=GUICtrlCreateLabel("Status:",10,180,400)
readmacfile()
setTimertoNow()
$boolTimerActive=0
GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        select 
            case $msg = $GUI_EVENT_CLOSE 
                ExitLoop
            case $msg = $mwbtnExit 
                ExitLoop
            case $msg = $mwbtnWakeupall 
                wol_all()
            case $msg = $mwbtnGetMac 
                getmacinrange()
            case $msg = $mwbtnGetMac 
                getmacinrange()
            case $msg = $mwbtnWakeupSelected 
                wol_selected()              
            case $msg = $mwbtnReadMacListFile 
                readmacfile()
            case $msg = $mwbtnActivateTimer
                if $boolTimerActive=1 Then
                    TimerDisable(0)
                Else
                    TimerDisable(1)
                endif
            case $msg = $mwbtnSetTimertoNow 
                setTimertoNow()


                
            EndSelect   
            if $boolTimerActive=1 Then
                CheckWakeup()
                sleep(100)
            endif
    WEnd
    GUIDelete()
    exit

; ===================================================================
; Function: setTimertoNow
;   sets the thre time controls to the current time 
; ===================================================================
func setTimertoNow()
    guictrlsetdata($mvinpWakeupTimeHH,@HOUR)
    guictrlsetdata($mvinpWakeupTimeMM,@MIN)
    guictrlsetdata($mvinpWakeupTimeSS,@SEC)
EndFunc

; ===================================================================
; Function: TimerDisable
;   Toggle for the Timer button 
; ===================================================================
func TimerDisable($TimerState)
    $boolTimerActive=$TimerState
    if $TimerState = "0" Then
        GUICtrlSetState($mwbtnExit,$GUI_ENABLE)
        GUICtrlSetState($mwbtnGetMac,$GUI_ENABLE)
        GUICtrlSetState($mwbtnWakeupall,$GUI_ENABLE)
        GUICtrlSetState($mwbtnWakeupSelected,$GUI_ENABLE)
        GUICtrlSetState($mvinpIpStart,$GUI_ENABLE)
        GUICtrlSetState($mvinpIpStop,$GUI_ENABLE)
        GUICtrlSetState($mvinpWakeupTimeHH,$GUI_ENABLE)
        GUICtrlSetState($mvinpWakeupTimeMM,$GUI_ENABLE)
        GUICtrlSetState($mvinpWakeupTimeSS,$GUI_ENABLE)
        GUICtrlSetState($mwbtnReadMacListFile,$GUI_ENABLE)
        GUICtrlSetState($mwbtnSetTimertoNow,$GUI_ENABLE)
        GUICtrlSetData($mwbtnActivateTimer," Activate Timer")
        setStatusMsg("Timer deactivated")
        
    Else
        GUICtrlSetState($mwbtnExit,$GUI_DISABLE)
        GUICtrlSetState($mwbtnGetMac,$GUI_DISABLE)
        GUICtrlSetState($mwbtnWakeupall,$GUI_DISABLE)
        GUICtrlSetState($mwbtnWakeupSelected,$GUI_DISABLE)
        GUICtrlSetState($mvinpIpStart,$GUI_DISABLE)
        GUICtrlSetState($mvinpIpStop,$GUI_DISABLE)
        GUICtrlSetState($mvinpWakeupTimeHH,$GUI_DISABLE)
        GUICtrlSetState($mvinpWakeupTimeMM,$GUI_DISABLE)
        GUICtrlSetState($mvinpWakeupTimeSS,$GUI_DISABLE)
        GUICtrlSetState($mwbtnReadMacListFile,$GUI_DISABLE)
        GUICtrlSetState($mwbtnSetTimertoNow,$GUI_DISABLE)       
        
        GUICtrlSetData($mwbtnActivateTimer," De-Activate Timer")

        EndIf
EndFunc


; ===================================================================
; Function: CheckWakeup
; critical only equal time will trigger (needs omething better like a small range)
; ===================================================================
func CheckWakeup()
    
    $strWakeupTime=GUICtrlRead($mvinpWakeupTimeHH)&GUICtrlRead($mvinpWakeupTimeMM)&GUICtrlRead($mvinpWakeupTimess)
    $strNow=@HOUR&@MIN&@SEC
    setStatusMsg("Current time:"&@HOUR&":"&@MIN&":"&@SEC)
    if $strNOW = $strWakeupTime Then
        SoundPlay(@WindowsDir & "\media\tada.wav",0)
        wol_all()
    EndIf
EndFunc 
; ===================================================================
; Function: FillTimeCombos
;          filling the controls with data 
; ===================================================================
func FillTimeCombos()
    for $i=1 to 23 
            GUICtrlSetData($mvinpWakeupTimeHH,$i)
        Next
    for $i=1 to 59
            GUICtrlSetData($mvinpWakeupTimeMM,$i)
            GUICtrlSetData($mvinpWakeupTimeSS,$i)
        Next
    
EndFunc


; ===================================================================
; Function: readmacfile
;           reads mac list in ini format
; ===================================================================
func readmacfile($filemaclist="MACLIST.DAT")
    if FileExists($filemaclist) Then
        $aMaclist=IniReadSection(@scriptdir&"\"&$filemaclist,"MACLISTE")
        _GUICtrlListView_DeleteAllItems($mwlvMacadresses) 
        for $i  = 1 to $aMaclist[0][0] 
                GUICtrlCreateListViewItem(""&$aMaclist[$i][1]&"|"&$aMaclist[$i][0]&"", $mwlvMacadresses)    
            Next
    EndIf
            
    
    EndFunc
; ===================================================================
; Function: getmacinrange
;           simple try to get all mac adresses from a given range (only last segment)
; ===================================================================
func getmacinrange()
    FileDelete(@ScriptDir&"\"&$filemaclist)
    $aIpStart=StringSplit(GUICtrlRead($mvinpIpStart),".")
    $aIpStop=StringSplit(GUICtrlRead($mvinpIpStop),".")
    
    
                for $IpSegD = $aIpStart[4] to $aIpStop[4]
                    get_mac($aIpStart[1]&"."&$aIpStart[2]&"."&$aIpStart[3]&"."&$IpSegD) 
                Next
                readmacfile()

EndFunc

; ===================================================================
; Function: wol_selected
;   sents magic paket to the macadress selected in listviw
; ===================================================================
func wol_selected()
    $aSelectedItems=_GUICtrlListView_GetSelectedIndices($mwlvMacadresses,true)
    if $aSelectedItems[0] > 0 Then
        $macadress=_GUICtrlListView_GetItemText($mwlvMacadresses,$aSelectedItems[1])
        for $adapter in $aBrowdcast 
            wol_adapter($adapter,$macadress)
        Next
        setStatusMsg("is "&$adapter&" awake?")
    EndIf
    
    
endfunc
; ===================================================================
; Function: wol_all
; 
; ===================================================================
func wol_all()
    
    for $adapter in $aBrowdcast 
        wol_adapter_all($adapter)
    Next
    setStatusMsg("All awake?")
    
endfunc
; ===================================================================
; Function: setStatusMsg($msgtext)
;           $msg    --- Message for status text
; ===================================================================
func setStatusMsg($msgtext)
    GUICtrlSetData($mwlblStatus,"Status:"&$msgtext)
endfunc
; ===================================================================
; Function: wol_adapter($adapter,$$macadress)
;           $adapter        --- is the ipadress of the adapter
;          $macadress       --- is the macadress
; ===================================================================

func wol_adapter($adapter,$macadress)
    if $adapter <> "0.0.0.0" Then
        $IPADRESS = StringSplit($adapter,".")
        $Broadcast = $IPADRESS[1] & "." & $IPADRESS[2] & "." & $IPADRESS[3] & "." & "255"

        $String=""
                setStatusMsg("Sent WOL via "&$Broadcast&" for:"&$macadress)
                WOL($Broadcast,$macadress)
    EndIf
    
    EndFunc

; ===================================================================
; Function: wol_adapter($adapter)
;           $adapter        --- is the ipadress of the adapter
; ===================================================================

func wol_adapter_all($adapter)
    if $adapter <> "0.0.0.0" Then
        $IPADRESS = StringSplit($adapter,".")
        $Broadcast = $IPADRESS[1] & "." & $IPADRESS[2] & "." & $IPADRESS[3] & "." & "255"

        $String=""
      
        FOR $macadress IN $MACAddressList
                setStatusMsg("Sent WOL via "&$Broadcast&" for:"&$macadress)
                WOL($Broadcast,$macadress)
                Sleep(1000)
        Next
    EndIf
    
    EndFunc

; ===================================================================
; Function: WOL($Broadcast,$element)
;          $Broadcast       --- is ipadress of adapter with 255 at the End
;           $MACAddress     --- is the macadress 
; ===================================================================

; Wake up on Lan Function (Open connection and broadcast to Lan)
Func WOL($Broadcast,$MACAddress)
UDPStartUp()
$connexion = UDPOpen($Broadcast,7)
UDPSend($connexion, GenerateMagicPacket($MACAddress))
UDPCloseSocket($connexion)
UDPShutdown()
EndFunc


; This function convert a MAC Address Byte (e.g. "1f") to a char
Func HexToChar($strHex)
    
    Return Chr(Dec($strHex))
    
EndFunc

; This function generate the "Magic Packet"
Func GenerateMagicPacket($strMACAddress)
    
    $MagicPacket = ""
    $MACData = ""
    
    For $p = 1 To 11 Step 2
        $MACData = $MACData & HexToChar(StringMid($strMACAddress, $p, 2))
    Next
    
    For $p = 1 To 6
        $MagicPacket = HexToChar("ff") & $MagicPacket
    Next
    
    For $p = 1 To 16
        $MagicPacket = $MagicPacket & $MACData
    Next
    
    Return $MagicPacket
    
EndFunc

; ===================================================================
; Function: get_mac($remote_ip,$filemaclist)
;           $remote_ip      --- remote ip
;           $filemaclist    --- file in ini format
; enhanced by TheSovereign - skip local mac adress
; ===================================================================
func get_mac($remote_ip,$filemaclist="MACLIST.DAT")
                    Ping($remote_ip,200)
                    if @error =0 Then
                        $arpinfo = Run(@ComSpec & " /c ARP -a "&$remote_ip, @SystemDir, @SW_HIDE, 2)
                        sleep(200)
                        $output = StdoutRead($arpinfo, -1)
                            $aOutputLine=StringSplit($output,@CRLF)
                            If UBound($aOutputLine) > 5 Then ; <=== added so script doesn't choke when processing the IP for the computer it's running on
                                $macadress=Stringmid($aOutputLine[7],25,17)
                                $macadress=StringReplace($macadress,"-","")
                                IniWrite(@ScriptDir&"\"&$filemaclist,"MACLISTE",$remote_ip,$macadress)
                                setStatusMsg("Found maclist "&$macadress)
                            EndIf ; <=== and this one...

                        Else
                            setStatusMsg("Host "&$remote_ip&" not reachable")
                            Return
                        endif
                    EndFunc

Source: https://www.autoitscript.com/forum/topic/29772-copyright-free-wake-on-lan-script/

 

Link to comment
Share on other sites

You could use WMI to extract this information from a remote computer. Please check Scriptomatic in the Example Scripts forum. It generates the needed AutoIt code for you.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

×
×
  • Create New...