Code : Tout sélectionner
#cs
Date : 08/06/2011
Name : Adressage IPv4
Description : ce programme a pour but de calcul de façon dynamique les informations sur un réseau
#ce
#include <GuiListBox.au3>
#include <GuiEdit.au3>
#include <Array.au3>
#Include <GuiIPAddress.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
;***************** Variable Globales *************************************************************
;Form
Global $Adressage_ip
;Label
Global $lbl_ip,$lbl_mask,$lbl_net,$lbl_broadcast,$lbl_slash,$lbl_mask_calc,$lbl_ip_compare,$lbl_ip_compare_answer
;InputBox
Global $inpip_ip,$inpip_mask,$inp_level,$inpip_compare
;Bouton
Global $btn_go,$btn_compare
;Group
Global $grp_result_ip,$grp_mask_calc,$grp_Ip_compare,$grp_Ip
;UpDownLevel
Global $UpDownLevel
;*************************************************************************************************
HotKeySet("{ESC}", "Close") ;Permet de quitter lapplication avec la touche Echap
_Main()
Func Create_GUI() ;Fonction de création de la GUI (interface graphique)
;Forme principale****************************************************************************
$Adressage_ip = GUICreate("Adressage IP", 350, 340, 500, 200) ;La forme principal est une fenetre ou on viendra imposer d'autres éléments dessus
;label
$lbl_ip = GUICtrlCreateLabel("Taper ici votre IP : ",20,20)
$lbl_mask = GUICtrlCreateLabel("Taper ici votre masque : ",20,50)
$lbl_net = GUICtrlCreateLabel("Réseau : ",50,120)
$lbl_broadcast = GUICtrlCreateLabel("Broadcast : ",50,150)
$lbl_slash = GUICtrlCreateLabel("/ : ", 50,212)
$lbl_mask_calc = GUICtrlCreateLabel(" ==> 255.255.0.0" ,120,212)
$lbl_ip_compare = GUICtrlCreateLabel("Que : " ,50,282)
;InputBox
$inpip_ip = _GUICtrlIpAddress_Create($Adressage_ip,137, 18)
$inpip_mask = _GUICtrlIpAddress_Create($Adressage_ip,137, 48)
$inpip_compare = _GUICtrlIpAddress_Create($Adressage_ip,80, 278)
$inp_level = GUICtrlCreateInput(16, 70, 210, 50, 20, 0x2001)
;Bouton
$btn_go = GUICtrlCreateButton("Go !", 275, 32)
$btn_compare = GUICtrlCreateButton(" Non ", 225, 277)
;Group
$grp_result_ip = GUICtrlCreateGroup("Résultat", 40, 80, 227, 95)
$grp_mask_calc = GUICtrlCreateGroup("Trouver son masque",40,182,200,60)
$grp_Ip_compare = GUICtrlCreateGroup("Suis-je sur le même réseau ?",40,252,240,60)
;UpDownLevel
$UpDownLevel = GUICtrlSetLimit(GUICtrlCreateUpdown($inp_level), 32, 0)
;~ **********************************************************************************************************
Opt("GUIOnEventMode", 1) ;Permet d'utiliser les évènement GUICtrlSetOnEvent
;~ *************** Evenements Boutons ****************************************
GUICtrlSetOnEvent($btn_go,"IpToNetwork")
;~ *************** Evenements InputBox ************************************
GUICtrlSetOnEvent($inp_level,"DmaskToBmask")
GUICtrlSetOnEvent($btn_compare,"IpCompare")
GUISetState(@SW_SHOW) ; Affiche la GUI
EndFunc ;==>Create_GUI
Func IpToNetwork()
Local $sortie = False
Local $binary_number_ip[4]
Local $binary_number_mask[4]
Local $res_net,$res_broadcast
If _GUICtrlIpAddress_IsBlank($inpip_ip) Then
MsgBox(48,"Attention ! ","Le champ IP est vide ou incomplet !",10)
$sortie=True
EndIf
If _GUICtrlIpAddress_IsBlank($inpip_mask) Then
MsgBox(48,"Attention ! ","Le champ masque est vide ou incomplet !",10)
$sortie=True
EndIf
If $sortie == False Then
Local $ip=_GUICtrlIpAddress_GetArray($inpip_ip)
Local $mask=_GUICtrlIpAddress_GetArray($inpip_mask)
For $i=0 To 3
$res_net = $res_net & "." & BitAND($mask[$i],$ip[$i])
$res_broadcast = $res_broadcast & "." & BitOR($ip[$i],BitXOR($mask[$i],255))
Next
$lbl_net = GUICtrlCreateLabel("Réseau : "& StringMid($res_net,2),50,120)
$lbl_broadcast = GUICtrlCreateLabel("Masque : "& StringMid($res_broadcast,2),50,150)
EndIf
EndFunc
Func DmaskToBmask()
Local $nb_mask = _GUICtrlEdit_GetText($inp_level)
Local $mem=0,$mem_lbl,$mem_calc
while $nb_mask >= 8
$nb_mask = $nb_mask - 8
$mem = $mem + 1
WEnd
$mem_calc = (255-(2^(8-$nb_mask))+1)
Switch $mem
Case 4
$mem_lbl = " ==> 255.255.255.255"
;afficher 255.255.255.255
Case 3
$mem_lbl = " ==> 255.255.255." & $mem_calc
;afficher 255.255.255.2^nb_mask
Case 2
$mem_lbl = " ==> 255.255." & $mem_calc & ".0"
;afficher 255.255.2^nb_mask.0
Case 1
$mem_lbl = " ==> 255." & $mem_calc & ".0.0"
;afficher 255.2^nb_mask.0.0
Case 0
$mem_lbl= " ==> "& $mem_calc &".0.0.0"
;afficher 2^nb_mask.0.0.0
EndSwitch
$lbl_mask_calc = GUICtrlCreateLabel($mem_lbl,120,212)
EndFunc
Func IpCompare()
Local $sortie = False
Local $binary_number_ip[4]
Local $binary_number_mask[4]
Local $res_net1,$res_net2
If _GUICtrlIpAddress_IsBlank($inpip_ip) Then
MsgBox(48,"Attention ! ","Le champ IP est vide ou incomplet !",10)
$sortie=True
EndIf
If _GUICtrlIpAddress_IsBlank($inpip_compare) Then
MsgBox(48,"Attention ! ","Le champ IP a comparer est vide ou incomplet !",10)
$sortie=True
EndIf
If _GUICtrlIpAddress_IsBlank($inpip_mask) Then
MsgBox(48,"Attention ! ","Le champ masque est vide ou incomplet !",10)
$sortie=True
EndIf
If $sortie == False Then
Local $ip1=_GUICtrlIpAddress_GetArray($inpip_ip)
Local $ip2=_GUICtrlIpAddress_GetArray($inpip_compare)
Local $mask=_GUICtrlIpAddress_GetArray($inpip_mask)
For $i=0 To 3
$res_net1 = $res_net1 & "." & BitAND($mask[$i],$ip1[$i])
Next
For $i=0 To 3
$res_net2 = $res_net2 & "." & BitAND($mask[$i],$ip2[$i])
Next
If $res_net1 = $res_net2 Then
GUICtrlSetData($btn_compare,"Oui")
Else
GUICtrlSetData($btn_compare,"Non")
EndIf
EndIf
EndFunc
Func Close()
Exit
EndFunc
Func _Main() ; Fonction Principale
Create_GUI() ;Création de la Forme graphique
While True ;Boucle infini
Sleep(1000) ;Evite un bouclage trop répétitif du programme
WEnd ;fin de boucle
EndFunc ;==>_Main