#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=wol_autoit.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include #include #include #include #include #Include #Include #include #include ;Récupération Mac adresse de la carte connexion au réseau local par WMI $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") $colItems = $objWMIService.ExecQuery( "SELECT * FROM Win32_NetworkAdapter where NetConnectionID = 'Connexion au réseau local'") For $objItem in $colItems $mac = $objItem.MACAddress $etat = $objItem.NetConnectionStatus Next ;Requete afin de récupérer le masque de sous réseau de la carte connexion au réseau local par WMI $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") $colNetAdapters = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE and MACAddress = '" & $mac & "'") Dim $tab[2] For $objItem in $colNetAdapters $tab = $objItem.IPSubnet $DefaultIPGateway = $objItem.DefaultIPGateway Next $pas =_ArrayToString($tab, ",") $passerelle = _ArrayToString($DefaultIPGateway, ",") ;Recherce du caractère "," utilisé dans windows vista ex: 255.255.255.0,64 sous xp ilya seulement 255.255.255.0 $pos = StringInStr($pas, ",") if $pos <> 0 then ;si caractère trouvé extraction du masque de sous réseau $pas = StringLeft($pas, $pos - 1) EndIf ;Masque de sous réseau $arrSubnetMask = StringSplit($pas, ".") $arrpasserelle = StringSplit($passerelle, ".") If IsArray($arrSubnetMask) <> 1 Then Exit EndIf $arrIPAddress = StringSplit(@IPAddress1, ".") If $arrSubnetMask[1] = 255 Then $strBroadcastIP = $arrIPAddress[1] Else $strBroadcastIP = 255 - $arrSubnetMask[1] EndIf if $etat <> 7 Then For $i = 2 To 4 If $arrSubnetMask[$i] = 255 Then $strBroadcastIP = $strBroadcastIP & "." & $arrIPAddress[$i] ElseIf $arrSubnetMask[$i] < 255 And $arrSubnetMask[$i] > 0 Then $diff = 255 - $arrSubnetMask[$i] $broad = $diff + $arrpasserelle[$i] $strBroadcastIP = $strBroadcastIP & "." & $broad Else $strBroadcastIP = $strBroadcastIP & "." & 255 - $arrSubnetMask[$i] EndIf Next $presencereseau = 1 Else $presencereseau = 0 EndIf if $presencereseau = 0 Then MsgBox(16,"Message important","ATTENTION votre poste n'est pas connecté au réseau") Endif $tableName = "wol" $dataBase = "wol.mdb" $query = "Select * From " & $tableName & " order by netbios" $frmwol = GUICreate("Wake on Lan", 800, 600) GUISetFont(10, 400, 0, "Tahoma") $listwake = GUICtrlCreateListView("NetBios | IP | Mac | En ligne", 16, 25, 640, 515, -1, BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)); Définition des entêtes de colonnes ;Définition de la largeur des colonnes GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 160) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 120) $lblinfo = GUICtrlCreateLabel("Veuillez patienter pendant la mise à jour de la liste SVP!", 16, 2, 640, 20, $SS_CENTER) $cmdOK = GUICtrlCreateButton("Réveil", 670, 40, 120, 40, BitOR($WS_GROUP, $BS_DEFPUSHBUTTON)) GUICtrlSetFont(-1, 11, 400, 0, "Tahoma") if $presencereseau = 0 Then GUICtrlSetState(-1, $GUI_DISABLE) EndIf $cmdping = GUICtrlCreateButton("Ping", 670, 80, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 11, 400, 0, "Tahoma") if $presencereseau = 0 Then GUICtrlSetState(-1, $GUI_DISABLE) EndIf $cmdnbtstat = GUICtrlCreateButton("Nbtstat", 670, 120, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 11, 400, 0, "Tahoma") if $presencereseau = 0 Then GUICtrlSetState(-1, $GUI_DISABLE) EndIf $cmdarret = GUICtrlCreateButton("Arrêter...", 670, 160, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 11, 400, 0, "Tahoma") if $presencereseau = 0 Then GUICtrlSetState(-1, $GUI_DISABLE) EndIf $cmdactualiser = GUICtrlCreateButton("Actualiser", 670, 200, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 11, 400, 0, "Tahoma") if $presencereseau = 0 Then GUICtrlSetState(-1, $GUI_DISABLE) EndIf $cmdScanner = GUICtrlCreateButton("Scanner... ", 250, 544, 150, 25, $WS_GROUP) GUICtrlSetFont(-1, 11, 400, 0, "Tahoma") if $presencereseau = 0 Then GUICtrlSetState(-1, $GUI_DISABLE) EndIf $cmdAjout = GUICtrlCreateButton("Ajouter...", 90, 572, 150, 25, $WS_GROUP) GUICtrlSetFont(-1, 11, 400, 0, "Tahoma") $cmdModif = GUICtrlCreateButton("Modifier... ", 250, 572, 150, 25, $WS_GROUP) GUICtrlSetFont(-1, 11, 400, 0, "Tahoma") $cmdSuppr = GUICtrlCreateButton("Supprimer", 410, 572, 150, 25, $WS_GROUP) GUICtrlSetFont(-1, 11, 400, 0, "Tahoma") $cmdfermer = GUICtrlCreateButton("Fermer", 685, 550, 109, 40, $WS_GROUP) GUICtrlSetFont(-1, 11, 400, 0, "Tahoma") GUICtrlSetState($listwake, $GUI_FOCUS) GUISetState(@SW_SHOW) _GUICtrlListView_RegisterSortCallBack($listwake) ;Appel de la fonction de remplissage de la listview RempliListe() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $cmdfermer Exit Case $listwake _GUICtrlListView_SortItems($listwake, GUICtrlGetState($listwake)) Case $cmdOK ;Bouton d'envoi du réveil ;Lecture du nom netbios de la listview $str = GUICtrlRead(GUICtrlRead($listwake)) $val2 = StringInStr($str, "|", 0, 1) $Netbiosname = Stringleft($str, $val2 - 1) if $Netbiosname = "" Then ;Si aucune ligne de la listview sélectionnée Msgbox (4096 + 16, "Message important", "Veuillez choisir un poste à démarrer SVP!") Else $adoCon = ObjCreate ("ADODB.Connection") $adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & @ScriptDir & "\" & $dataBase) $adoRs = ObjCreate ("ADODB.Recordset") $adoRs.CursorType = 1 $adoRs.LockType = 3 ;Requete sur le nom netbios pour extraction de l'adresse MAC $req = "select * from wol where netbios = '" & $Netbiosname & "'" $adoRs.Open ($req, $adoCon) $adoRs.movefirst $MACAddress = $adoRs.Fields("mac").value $ip = $adoRs.Fields("ip").value $adoRs.Close $adoCon.Close ;Mise en forme de l'adresse MAC $MACAddress = StringReplace($MACAddress, ":", "") $MACAddress = StringReplace($MACAddress, "-", "") UDPStartUp() $connexion = UDPOpen($strBroadcastIP, 7) $res = UDPSend($connexion, GenerateMagicPacket($MACAddress)) MsgBox(4096 + 64, "Réveil initié", "Le réveil de " & $Netbiosname & " a été initié sur la Mac Adresse " & StringUpper($MACAddress)) UDPCloseSocket($connexion) UDPShutdown() Run ("cmd") sleep(500) Send ("ping " & $ip & " -t {ENTER}") EndIf Case $cmdModif ;Lecture du nom netbios dans la listview $modif = _GUICtrlListView_GetItemTextString($listwake, -1) ;Recherche de la position de la première instance du caractère "|" dans la ligne issue de la listview $val2 = StringInStr($modif, "|", 0, 1) ;Extraction de la ligne de la listview du Nom Netbios moyennant la position de la première instance du caractère "|" $modifnetbios = Stringleft($modif, $val2 - 1) ;Recherche de la position de la deuxième instance du caractère "|" dans la ligne issue de la listview $val4 = StringInStr($modif, "|", 0, 2) ;Extraction de la ligne de la listview de l'adresse ip en partant du caractére suivant la 1ère instance de "|" ;en comptant un nombre de caractères égal à la position de la deuxième instance de "|" moins la position de la première instance de "|" moins 1 caractère $modifip = StringMid($modif, $val2 + 1, ($val4 - $val2) - 1) if $modifip <> "" Then ;Si une ligne a été sélectionnée Ajout($modifnetbios, $modifip) ;Appel de la fonction qui ouvrira le formulaire de saisie Else ;Si aucune ligne sélectionnée Msgbox (4096 + 16, "Message important", "Veuillez choisir un poste à modifier SVP!") EndIf Case $cmdAjout Ajout("ajout", "") Case $cmdScanner Scan() Case $cmdactualiser RempliListe() Case $cmdarret ;Lecture du nom netbios dans la listview $Netbiosname = _GUICtrlListView_GetItemTextString($listwake, -1) $val2 = StringInStr($Netbiosname, "|", 0, 1) $Netbiosname = Stringleft($Netbiosname, $val2 - 1) if $Netbiosname <> "" Then ;Si une ligne a été sélectionnée Arret($Netbiosname) ;Appel de la fonction qui arrêtera le poste Else ;Si aucune ligne sélectionnée Msgbox (4096 + 16, "Message important", "Veuillez choisir un poste à arrêter SVP!") EndIf Case $cmdSuppr ;Lecture du nom netbios dans la listview $modif = _GUICtrlListView_GetItemTextString($listwake, -1) ;Recherche de la position de la première instance du caractère "|" dans la ligne issue de la listview $val2 = StringInStr($modif, "|", 0, 1) ;Extraction de la ligne de la listview du Nom Netbios moyennant la position de la première instance du caractère "|" $modifnetbios = Stringleft($modif, $val2 - 1) ;Recherche de la position de la deuxième instance du caractère "|" dans la ligne issue de la listview $val4 = StringInStr($modif, "|", 0, 2) ;Extraction de la ligne de la listview de l'adresse ip en partant du caractére suivant la 1ère instance de "|" ;en comptant un nombre de caractères égal à la position de la deuxième instance de "|" moins la position de la première instance de "|" moins 1 caractère $modifip = StringMid($modif, $val2 + 1, ($val4 - $val2) - 1) if $modifnetbios <> "" Then ;Si une ligne a été sélectionnée Supprime($modifnetbios, $modifip) ;Appel de la fonction qui supprimera les données Else ;Si aucune ligne sélectionnée Msgbox (4096 + 16, "Message important", "Veuillez choisir un poste à supprimer SVP!") EndIf case $cmdping ;Lecture du nom netbios de la listview $str = GUICtrlRead(GUICtrlRead($listwake)) $val2 = StringInStr($str, "|", 0, 1) $Netbiosname = Stringleft($str, $val2 - 1) if $Netbiosname = "" Then ;Si aucune ligne de la listview sélectionnée Msgbox (4096 + 16, "Message important", "Veuillez choisir un poste à pinguer!") Else $adoCon = ObjCreate ("ADODB.Connection") $adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & @ScriptDir & "\" & $dataBase) $adoRs = ObjCreate ("ADODB.Recordset") $adoRs.CursorType = 1 $adoRs.LockType = 3 ;Requete sur le nom netbios pour extraction de l'adresse MAC $req = "select * from wol where netbios = '" & $Netbiosname & "'" $adoRs.Open ($req, $adoCon) $adoRs.movefirst $ip = $adoRs.Fields("ip").value $adoRs.Close $adoCon.Close Run ("cmd") sleep(500) Send ("ping " & $ip & " -t {ENTER}") EndIf case $cmdnbtstat ;Lecture du nom netbios de la listview $str = GUICtrlRead(GUICtrlRead($listwake)) $val2 = StringInStr($str, "|", 0, 1) $Netbiosname = Stringleft($str, $val2 - 1) if $Netbiosname = "" Then ;Si aucune ligne de la listview sélectionnée Msgbox (4096 + 16, "Message important", "Veuillez choisir un poste pour effectuer le Nbtstat!") Else $adoCon = ObjCreate ("ADODB.Connection") $adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & @ScriptDir & "\" & $dataBase) $adoRs = ObjCreate ("ADODB.Recordset") $adoRs.CursorType = 1 $adoRs.LockType = 3 ;Requete sur le nom netbios pour extraction de l'adresse MAC $req = "select * from wol where netbios = '" & $Netbiosname & "'" $adoRs.Open ($req, $adoCon) $adoRs.movefirst $ip = $adoRs.Fields("ip").value $adoRs.Close $adoCon.Close Run ("cmd") sleep(500) Send ("nbtstat -a " & $ip & " {ENTER}") EndIf EndSwitch WEnd ;################################################################################# ; Fonctions ;################################################################################# ; 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 ;################################################################################# Func Ajout($modifnetbios, $modifip) if $modifnetbios <> "ajout" Then $adoCon = ObjCreate ("ADODB.Connection") $adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & @ScriptDir & "\" & $dataBase) $adoRs = ObjCreate ("ADODB.Recordset") $adoRs.CursorType = 1 $adoRs.LockType = 3 $req = "select * from wol where ip = '" & $modifip & "'" $adoRs.Open ($req, $adoCon) $Netbiosname = $adoRs.Fields("Netbios").value $IPAddresse = $adoRs.Fields("ip").value $MACAddress = $adoRs.Fields("mac").value $adoRs.Close $adoCon.Close EndIf if $modifnetbios = "ajout" then $frmNPoste = GUICreate("Nouveau poste", 496, 150) GUISetFont(10, 400, 0, "Tahoma") Else $frmNPoste = GUICreate("Modifier le poste " & $Netbiosname, 496, 150) GUISetFont(10, 400, 0, "Tahoma") EndIf if $modifnetbios = "ajout" then $InNetbios = GUICtrlCreateInput("", 152, 20, 181, 24) Else $InNetbios = GUICtrlCreateInput(StringUpper($Netbiosname), 152, 20, 181, 24) EndIf $IPAddress = _GUICtrlIpAddress_Create($frmNPoste, 152, 52, 177, 25) if $modifnetbios = "ajout" then _GUICtrlIpAddress_Set($IPAddress, "0.0.0.0") Else _GUICtrlIpAddress_Set($IPAddress, $IPAddresse) EndIf if $modifnetbios = "ajout" then $InMAc = GUICtrlCreateInput("", 152, 88, 189, 24) Else $InMAc = GUICtrlCreateInput(StringUpper($MACAddress), 152, 88, 189, 24) EndIf $lblNetbios = GUICtrlCreateLabel("Netbios:", 24, 24, 123, 20, $SS_RIGHT) $lblIP = GUICtrlCreateLabel("IP:", 24, 56, 123, 20, $SS_RIGHT) $lblmac = GUICtrlCreateLabel("MAC Adresse:", 24, 92, 123, 20, $SS_RIGHT) $cmdOK2 = GUICtrlCreateButton("OK", 376, 20, 101, 41, $WS_GROUP) $cmdAnnuler = GUICtrlCreateButton("Annuler", 376, 68, 101, 41, $WS_GROUP) GUISetState() While 1 $nMsg2 = GUIGetMsg() Select Case $nMsg2 = $GUI_EVENT_CLOSE if WinActive("Nouveau poste") Then GUIDelete($frmNPoste) ExitLoop Elseif WinActive("Modifier le poste " & $Netbiosname) Then GUIDelete($frmNPoste) ExitLoop EndIf Case $nMsg2 = $cmdAnnuler if WinActive("Nouveau poste") Then GUIDelete($frmNPoste) ExitLoop Elseif WinActive("Modifier le poste " & $Netbiosname) Then GUIDelete($frmNPoste) ExitLoop EndIf Case $nMsg2 = $cmdOK2 $adoCon = ObjCreate ("ADODB.Connection") $adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & @ScriptDir & "\" & $dataBase) $adoRs = ObjCreate ("ADODB.Recordset") $adoRs.CursorType = 1 $adoRs.LockType = 3 if $modif = "ajout" then $adoRs.Open ($query, $adoCon) if $adoRs.recordcount <> 0 Then $adoRs.movefirst Endif $adoRs.Addnew Else $adoRs.Open ($req, $adoCon) $adoRs.movefirst EndIf $adoRs.Fields("Netbios").value = GUICtrlRead($InNetbios) $adoRs.Fields("ip").value = _GUICtrlIpAddress_Get($IPAddress) $adoRs.Fields("mac").value = GUICtrlRead($InMAc) $adoRs.Update $adoRs.Close $adoCon.Close Sleep(500) RempliListe() Sleep(500) GUIDelete($frmNPoste) ExitLoop EndSelect WEnd EndFunc ;################################################################################# Func Scan() $arrIPPoste = StringSplit(@IPAddress1, ".") $IPDebut = $arrIPPoste[1] & "." & $arrIPPoste[2] & "." & $arrIPPoste[3] & ".1" $IPFin = $arrIPPoste[1] & "." & $arrIPPoste[2] & "." & $arrIPPoste[3] & ".255" $frmScan = GUICreate("Scanner la plage", 640, 520) GUISetFont(10, 400, 0, "Tahoma") $IPAddress1 = _GUICtrlIpAddress_Create($frmScan, 210, 10, 177, 25) _GUICtrlIpAddress_Set($IPAddress1, $IPDebut) $IPAddress2 = _GUICtrlIpAddress_Create($frmScan, 210, 40, 177, 25) _GUICtrlIpAddress_Set($IPAddress2, $IPFin) $listscan = GUICtrlCreateListView("NetBios | IP | Mac", 20, 100, 500, 380, -1, BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)); Définition des entêtes de colonnes ;Définition de la largeur des colonnes GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 140) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 140) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 180) $lblIPAddress1 = GUICtrlCreateLabel("Adresse de début:", 50, 14, 155, 20, $SS_RIGHT) $lblIPAddress2 = GUICtrlCreateLabel("Adresse de fin:", 50, 44, 155, 20, $SS_RIGHT) $lblIPAddress3 = GUICtrlCreateLabel("", 50, 74, 155, 20, $SS_RIGHT) $lblIPAddress4 = GUICtrlCreateLabel("", 210, 74, 155, 20) GUICtrlSetFont(-1, 10, 800) GUICtrlSetColor(-1, 0xff0000) $cmdScan = GUICtrlCreateButton("Scanner", 530, 20, 101, 41, $WS_GROUP) $cmdAjouter = GUICtrlCreateButton("Ajouter à la liste", 220, 485, 140, 30, $WS_GROUP) $cmdAnnuler3 = GUICtrlCreateButton("Annuler", 530, 68, 101, 41, $WS_GROUP) GUICtrlSetState($cmdAjouter, $GUI_HIDE) GUISetState(@SW_SHOW) While 1 $nMsg3 = GUIGetMsg() Select Case $nMsg3 = $GUI_EVENT_CLOSE if WinActive("Scanner la plage") Then GUIDelete($frmScan) ExitLoop EndIf Case $nMsg3 = $cmdAnnuler3 if WinActive("Scanner la plage") Then GUIDelete($frmScan) ExitLoop EndIf Case $nMsg3 = $cmdScan $IPDebut = _GUICtrlIpAddress_Get($IPAddress1) $IPFin = _GUICtrlIpAddress_Get($IPAddress2) $arrIPDebut = StringSplit($IPDebut, ".") $arrIPFin = StringSplit($IPFin, ".") $3octetDebut = $arrIPDebut[3] $3octetFin = $arrIPFin[3] $4octetDebut = $arrIPDebut[4] $4octetFin = $arrIPFin[4] $adoCon = ObjCreate ("ADODB.Connection") $adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & @ScriptDir & "\" & $dataBase) $adoRs = ObjCreate ("ADODB.Recordset") $adoRs.CursorType = 1 $adoRs.LockType = 3 $adoRs.Open ("delete * from scan", $adoCon) ;suppression des éléments existant $adoRs.Open ("Select * from scan", $adoCon) For $s = $3octetDebut to $3octetFin For $i = $4octetDebut to $4octetFin $adr = $arrIPDebut[1] & "." & $arrIPDebut[2] & "." & $s & "." & $i GUICtrlSetData($lblIPAddress3, "Adresse scannée:") GUICtrlSetData($lblIPAddress4, $adr) $var = Ping($adr,250) if $var Then ;si réponse au ping $WshShell = ObjCreate("Wscript.shell") $Commnbtsat = "cmd /c nbtstat.exe -a " & $adr & " | find /I ""<00> UNIQUE""" ;exécution de la ligne de commande de nbtstat $Resnbtsat = $WshShell.Run($Commnbtsat, 0, TRUE) ;Exécution nbtsat if $Resnbtsat = 0 then ;Si réponse au nbtstat If FileExists(@ScriptDir & "\result.txt") Then FileDelete(@ScriptDir & "\result.txt") EndIf $fileresult = FileOpen(@ScriptDir & "\result.txt", 10) FileClose($fileresult) $Commnbtsatfic = "cmd /c nbtstat.exe -a " & $adr & " >""" & @ScriptDir & """\result.txt" ;Ligne de commande avec résultat du Nbtstat dans un fichier $ResCommnbtsatfic = $WshShell.Run($Commnbtsatfic, 0, TRUE) ;Exécution de la ligne de commande $nbtstat = FileOpen(@ScriptDir & "\result.txt", 0) ; Vérification de la disponibilité du fichier If $nbtstat = -1 Then Exit EndIf $h = 0 ;Initiation du compteur de lignes ; Lecture du fichier afin de compter les lignes While 1 $lignenbtstat = FileReadLine($nbtstat) If @error = -1 Then ExitLoop $h = $h + 1 ;comptage des lignes Wend local $Arrnbtstat[$h] ;Déclaration du tableau avec le nombre de lignes ;Stockage dans un tableau des infos lues dans le fichier result.txt For $j = 0 to ($h - 1) $lignenbtstat = FileReadLine($nbtstat, $j + 1) $Arrnbtstat[$j] = $lignenbtstat NExt For $k = 0 to UBound($Arrnbtstat) - 1 ;Recherche de la ligne Adresse Mac if StringMid($Arrnbtstat[$k],5,7) = "Adresse" then ;Lecture de la ligne $Adrmac = StringMid($Arrnbtstat[$k],19,17) EndIf ;Recherche de la ligne <00> UNIQUE if StringMid($Arrnbtstat[$k],20,12) = "<00> UNIQUE" then ;Lecture de la ligne $pos = StringInStr($Arrnbtstat[$k], "<",0,1) $Net = Stringleft($Arrnbtstat[$k], $pos - 1) $Netbiosname = StringStripWS($Net, 3) endif Next FileClose($nbtstat) ;Fermeture du fichier ;Affichage dans la listview du scan GUICtrlCreateListViewItem($Netbiosname & "|" & $adr & "|" & $Adrmac, $listscan) ;Ici intégrer les données scannées dans la table scan $adoRs.Addnew $adoRs.Fields("Netbios").value = $Netbiosname $adoRs.Fields("ip").value = $adr $adoRs.Fields("mac").value = $Adrmac $adoRs.Update Else ;Si pas de réonse à Nbtstat GUICtrlCreateListViewItem("Nom inconnu |" & $adr & "| ", $listscan) ;Ici intégrer les données scannées dans la table scan $adoRs.Addnew $adoRs.Fields("Netbios").value = "Nom inconnu" $adoRs.Fields("ip").value = $adr $adoRs.Fields("mac").value = "" $adoRs.Update EndIf EndIf $adr = "" $Netbiosname = "" $Adrmac = "" Next $i = 0 Next $adoRs.Close GUICtrlSetData($lblIPAddress4, "Fin du scan!") GUICtrlSetState($cmdAjouter, $GUI_SHOW) Case $nMsg3 = $cmdAjouter $adoCon = ObjCreate ("ADODB.Connection") $adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & @ScriptDir & "\" & $dataBase) $adoRs = ObjCreate ("ADODB.Recordset") $adoRst = ObjCreate ("ADODB.Recordset") $adoCompte = ObjCreate ("ADODB.Recordset") $adoRs.CursorType = 1 $adoRs.LockType = 3 $adoRst.CursorType = 1 $adoRst.LockType = 3 $adoCompte.CursorType = 1 $adoCompte.LockType = 3 ;Ouverture de la table wol $adoRs.Open ("Select * from wol", $adoCon) if @error Then $adoRs.movefirst EndIf ;Ouverture de la table scan $adoRst.Open ("Select * from scan", $adoCon) if @error Then $adoRst.movefirst EndIf Do $Netbiosname = $adoRst.Fields("Netbios").value $ipadr = $adoRst.Fields("ip").value $Adrmac = $adoRst.Fields("mac").value $adoCompte.open("select * from wol where netbios = '" & $Netbiosname & "' and ip = '" & $ipadr & "'", $adoCon) if $adoCompte.recordcount = 0 Then $adoRs.Addnew $adoRs.Fields("Netbios").value = $Netbiosname $adoRs.Fields("ip").value = $ipadr $adoRs.Fields("mac").value = $Adrmac $adoRs.Update ElseIf $adoCompte.recordcount = 1 Then $adoCompte.Fields("ip").value = $ipadr $adoCompte.Fields("mac").value = $Adrmac $adoCompte.Update EndIf $adoCompte.Close $adoRst.Movenext Until $adoRst.Eof $adoRs.Close $adoRst.Close $adoCon.close Sleep(500) RempliListe() Sleep(500) GUIDelete($frmScan) ExitLoop EndSelect WEnd EndFunc ;################################################################################# Func Arret($Netbiosname) $frmScan = GUICreate("Arrêt du poste " & $Netbiosname, 510, 180) GUISetFont(10, 400, 0, "Tahoma") GUIStartGroup() $Arreter = GUICtrlCreateRadio("Mettre le poste hors tension", 110, 10, 200, 20) $Reboot = GUICtrlCreateRadio("Redémarrer le poste", 110, 40, 200, 20) GUICtrlSetState($Arreter, $GUI_CHECKED) $ctrltimer = GUICtrlCreateInput("15", 110, 70, 50, 20) $updown = GUICtrlCreateUpdown($ctrltimer) $commentaire = GUICtrlCreateEdit("", 110, 100, 280, 50, $ES_AUTOVSCROLL) $lbltimer = GUICtrlCreateLabel("Délai:", 15, 74, 90, 20, $SS_RIGHT) $lblcommentaire = GUICtrlCreateLabel("Commentaire:", 15, 104, 90, 20, $SS_RIGHT) $cmdGo = GUICtrlCreateButton("Go", 400, 20, 101, 41, BitOR($WS_GROUP, $BS_DEFPUSHBUTTON)) $cmdAnnuler3 = GUICtrlCreateButton("Annuler", 400, 68, 101, 41, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg3 = GUIGetMsg() Select Case $nMsg3 = $GUI_EVENT_CLOSE if WinActive("Arrêt du poste") Then GUIDelete($frmScan) ExitLoop EndIf Case $nMsg3 = $cmdAnnuler3 if WinActive("Arrêt du poste") Then GUIDelete($frmScan) ExitLoop EndIf Case $nMsg3 = $cmdGo if GUICtrlRead($Arreter) = 1 Then ;Arret choisi $type = "s" Else ;Reboot choisi $type = "r" EndIf $timer = GUICtrlRead($ctrltimer) $WshShell = ObjCreate("Wscript.shell") if GUICtrlRead($commentaire) = "" Then $strShutdown = "shutdown.exe -m \\" & $Netbiosname & " -"& $type & " -t " & $timer & " -f " Else $strShutdown = "shutdown.exe -m \\" & $Netbiosname & " -"& $type & " -c """ & GUICtrlRead($commentaire) & """ -t " & $timer & " -f" EndIf $Rescomm = $WshShell.Run($strShutdown, 0, TRUE) ;Exécution de la ligne de commande if $Rescomm = 0 Then if $type = "s" Then MsgBox(64,"Message de confirmation","La commande d'arrêt a bien été envoyée au poste " & $Netbiosname) Else MsgBox(64,"Message de confirmation","La commande de redémarrage a bien été envoyée au poste " & $Netbiosname) EndIf Else MsgBox(16,"Message important","Une erreur est survenue lors de l'envoi de lacommande Shutdown au poste " & $Netbiosname) EndIf EndSelect WEnd EndFunc ;################################################################################# Func RempliListe() GUICtrlSetData($lblinfo, "Veuillez patienter pendant la mise à jour de la liste SVP!") GUICtrlSetFont($lblinfo, 11, 600, 0, "Tahoma") GUICtrlSetColor($lblinfo, 0xff0000) _GUICtrlListView_DeleteAllItems($listwake) ;Effacement de la listview $adoCon = ObjCreate ("ADODB.Connection") $adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & @ScriptDir & "\" & $dataBase) $adoRs = ObjCreate ("ADODB.Recordset") $adoRs.CursorType = 1 $adoRs.LockType = 3 $adoRs.Open ($query, $adoCon) if $adoRs.recordcount <> 0 Then $adoRs.movefirst ;Remplissage de la listview avec les données Do $Netbios= StringUpper($adoRs.Fields("Netbios").value) $IPAddress= $adoRs.Fields("ip").value $MACAddresse = StringUpper($adoRs.Fields("mac").value) $var = Ping($IPAddress,250) if $var Then $up = "OUI" Else $up = "NON" Endif GUICtrlCreateListViewItem($Netbios & "|" & $IPAddress & "|" & $MACAddresse & "|" & $up, $listwake) $adoRs.Movenext Until $adoRs.EOF $adoRs.Close $adoCon.Close Endif GUICtrlSetData($lblinfo, "Toutes les informations de la liste sont à jour") GUICtrlSetColor($lblinfo, 0x33CC00) Sleep(2000) if $presencereseau = 0 Then GUICtrlSetData($lblinfo, "ATTENTION votre poste n'est pas sur le réseau") GUICtrlSetColor($lblinfo, 0xff0000) EndIf EndFunc ;################################################################################# Func Supprime($suppr, $ip) if MsgBox (4096 + 16 + 4, "Confirmation de suppression", "Voulez vous vraiment supprimer le poste " & $suppr & " ?") = 6 then $adoCon = ObjCreate ("ADODB.Connection") $adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & @ScriptDir & "\" & $dataBase) $adoRs = ObjCreate ("ADODB.Recordset") $adoRs.CursorType = 1 $adoRs.LockType = 3 $reqsuppr = "select * from wol where ip = '" & $ip & "'" $adoRs.Open ($reqsuppr, $adoCon) $adoRs.movefirst ;Suppression des données Do $adoRs.Delete $adoRs.Movenext Until $adoRs.EOF $adoRs.Close $adoCon.Close Sleep(100) RempliListe() Sleep(100) EndIf EndFunc