Pour changer l'ip de chacune d'elle (afin de les intégrer au réseau du client) je devais changer l'ip de mon pc pour accéder a l'interface de la camera ...
Grâce au recherche sur le forum et autre je me suis fais un petit interface de gestion d'ip...
Et la j'arrive pas a finir! il me manque la commande "netsh" pour revenir en dhcp (ip automatique)! Que j'activerais avec le radio button
Un p'tit coup de main ?
► Afficher le texte
Code : Tout sélectionner
#RequireAdmin
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#Include <File.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Opt("GUIOnEventMode", 1)
;#############################################################################################################################################
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("IP_CONFIG", 434, 258, 192, 124)
$Group1 = GUICtrlCreateGroup("Détails", 8, 8, 217, 233)
$Radio1 = GUICtrlCreateRadio("Static", 57, 24, 65, 17)
$Radio2 = GUICtrlCreateRadio("Dhcp", 131, 24, 73, 17)
$Input1 = GUICtrlCreateInput(" . . . ", 104, 56, 97, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Input2 = GUICtrlCreateInput(" . . . ", 104, 91, 97, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Input3 = GUICtrlCreateInput(" . . . ", 104, 127, 97, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Input4 = GUICtrlCreateInput(" . . . ", 104, 162, 97, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Label1 = GUICtrlCreateLabel("IPv4 = ", 32, 59, 38, 17)
$Label2 = GUICtrlCreateLabel("Masque = ", 32, 94, 54, 17)
$Label3 = GUICtrlCreateLabel("Paserelle = ", 32, 130, 59, 17)
$Label4 = GUICtrlCreateLabel("Dns = ", 32, 165, 35, 17)
$Button1 = GUICtrlCreateButton("OK", 80, 200, 75, 25)
GUICtrlSetOnEvent(-1, "change_ip")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Config", 240, 8, 185, 89)
$Combo1 = GUICtrlCreateCombo("Choix Config =", 256, 32, 153, 25)
GUICtrlSetOnEvent(-1,"choix_ip_config")
$Button2 = GUICtrlCreateButton("Gestion", 296, 64, 75, 25)
GUICtrlSetOnEvent(-1,"gui_gestion_ip_config")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Console", 240, 104, 185, 137)
$Edit1 = GUICtrlCreateEdit("", 247, 120, 170, 113, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN))
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "closed")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("GESTION_IP_CONFIG", 240, 258, 700, 124)
$Input5_2 = GUICtrlCreateInput("", 104, 14, 97, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Input2_2 = GUICtrlCreateInput(" . . . ", 105, 81, 97, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Input1_2 = GUICtrlCreateInput(" . . . ", 105, 46, 97, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Input3_2 = GUICtrlCreateInput(" . . . ", 105, 117, 97, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Input4_2 = GUICtrlCreateInput(" . . . ", 105, 152, 97, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Label5_2 = GUICtrlCreateLabel("Nom = ", 33, 19, 35, 17)
$Label1_2 = GUICtrlCreateLabel("IPv4 =", 33, 49, 38, 17)
$Label2_2 = GUICtrlCreateLabel("Masque =", 33, 84, 54, 17)
$Label3_2 = GUICtrlCreateLabel("Paserelle =", 33, 120, 59, 17)
$Label4_2 = GUICtrlCreateLabel("Dns =", 33, 155, 35, 17)
$Button2_2 = GUICtrlCreateButton("Nouveau", 27, 194, 59, 25)
GUICtrlSetOnEvent(-1,"nouvelle_config")
$Button1_2 = GUICtrlCreateButton("Supprimer", 89, 194, 59, 25)
GUICtrlSetOnEvent(-1,"effacer_config")
$Button3_2 = GUICtrlCreateButton("Enregistrer", 151, 194, 59, 25)
GUICtrlSetOnEvent(-1,"enregistrer_config")
$Button4_2 = GUICtrlCreateButton("Suivant", 120, 226, 90, 25)
GUICtrlSetOnEvent(-1,"affiche_ip_plus1")
$Button5_2 = GUICtrlCreateButton("Retour", 27, 226, 90, 25)
GUICtrlSetOnEvent(-1,"affiche_ip_moins1")
GUISetOnEvent($GUI_EVENT_CLOSE, "closed_gui_2")
#EndRegion ### END Koda GUI section ###
;#############################################################################################################################################
HotKeySet("{F5}","closed")
Global $ipv4,$masque,$passerelle,$num_ip = 1,$affiche
Global $netname = "Connexion au réseau local"
Global $newIp = "192.168.1.35"
Global $newSubnet = "255.255.255.0"
Global $newDG = "192.168.1.1"
Global $dns = "192.168.1.1"
;#############################################################################################################################################
if FileExists(@ScriptDir& "\" & "ipconfig.ini") Then
Else
_FileCreate(@ScriptDir& "\" & "ipconfig.ini")
EndIf
Local $choi = IniReadSectionNames(@ScriptDir& "\" & "ipconfig.ini")
;_ArrayDisplay($choi)
for $i = 1 to UBound($choi,1) -1
GUICtrlSetData($Combo1,$choi[$i])
Next
;#############################################################################################################################################
info_ip_config()
While 1
Sleep(20)
WEnd
;#############################################################################################################################################
Func change_ip()
$newIp = GUICtrlRead($Input1)
$newSubnet = GUICtrlRead($Input2)
$newDG = GUICtrlRead($Input3)
$dns = GUICtrlRead($Input4)
Runwait ('netsh interface ip set address name=' & '"' & $netname & '" static ' & $newIp & ' '& $newSubnet & ' ' & $newDG & ' 1',"",@SW_Hide)
RunWait('netsh interface ip set dns name=' & '"' & $netname & '"' & ' source=static addr= '& $dns, "", @SW_HIDE)
;Runwait ('netsh interface ip set address name=' & '"' & $netname & '" source=dhcp',"",@SW_Hide)
MsgBox(0,"","config changer")
info_ip_config()
EndFunc
Func info_ip_config();effectue une invite de commande "ipconfig" en mode cacher, recupere les infos dans un fichier text pour le parser et afficher les infos choisi
Local $foo = Run(@ComSpec & " /c ipconfig", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
While 1
$line = StdoutRead($foo)
If @error Then ExitLoop
if $line <> "" Then FileWrite(@ScriptDir& "\" & "tempo_ipconfig.txt",$line)
Wend
$file = FileOpen(@ScriptDir& "\" & "tempo_ipconfig.txt", 0)
Local $trouve
While 1
$ligne = FileReadLine($file)
if StringInStr($ligne,"IPv4") Then
$array = StringSplit ( $ligne,":")
;_ArrayDisplay($array)
$ipv4 = "IPv4 = "& $array[2]
Else
;$ipv4 = ""
EndIf
If StringInStr($ligne,"Masque") Then
$array = StringSplit ( $ligne,":")
;_ArrayDisplay($array2)
$masque = "Masque = "& $array[2]
Else
;$masque = ""
EndIf
If StringInStr($ligne,"Passerelle") Then
$array = StringSplit ( $ligne,":")
;_ArrayDisplay($array2)
$passerelle = "Passerelle = "& $array[2]
ExitLoop
Else
;$passerelle = ""
EndIf
;if $ipv4 = "" And $masque = "" And $passerelle = ""Then
;MsgBox(0,"","Média déconnecter !!")
;ExitLoop
;Else
;EndIf
WEnd
;MsgBox(0,"",$ipv4 & @CRLF & $masque & @CRLF & $passerelle)
GUICtrlSetData($Edit1,@ComputerName &@CRLF& @MDAY&"/"&@MON&"/"&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC &@CRLF& @CRLF & $ipv4 & @CRLF & $masque & @CRLF & $passerelle)
FileClose(@ScriptDir& "\" & "tempo_ipconfig.txt")
FileDelete(@ScriptDir& "\" & "tempo_ipconfig.txt")
EndFunc
Func gui_gestion_ip_config()
GUISetState(@SW_SHOW,$Form2)
affiche_ip()
EndFunc
Func choix_ip_config();envoi la config choisi dans le "inputs" ou les infos seront lu pour appliquer la config
;MsgBox(0,"",GUICtrlRead($Combo1))
GUICtrlSetData($Input1,IniRead(@ScriptDir& "\" & "ipconfig.ini",GUICtrlRead($Combo1),"IPv4",""))
GUICtrlSetData($Input2,IniRead(@ScriptDir& "\" & "ipconfig.ini",GUICtrlRead($Combo1),"masque",""))
GUICtrlSetData($Input3,IniRead(@ScriptDir& "\" & "ipconfig.ini",GUICtrlRead($Combo1),"passerelle",""))
GUICtrlSetData($Input4,IniRead(@ScriptDir& "\" & "ipconfig.ini",GUICtrlRead($Combo1),"dns",""))
EndFunc
Func affiche_ip();affiche les infos de differentes config dans la gui "gestion config"
$affiche = IniReadSectionNames(@ScriptDir& "\" & "ipconfig.ini")
if $num_ip > UBound($affiche)-1 Then $num_ip = 1
if $num_ip < 1 Then $num_ip = UBound($affiche)-1
;_ArrayDisplay($affiche)
GUICtrlSetData($Input5_2,$affiche[$num_ip])
GUICtrlSetData($Input1_2,IniRead(@ScriptDir& "\" & "ipconfig.ini",$affiche[$num_ip],"IPv4",""))
GUICtrlSetData($Input2_2,IniRead(@ScriptDir& "\" & "ipconfig.ini",$affiche[$num_ip],"masque",""))
GUICtrlSetData($Input3_2,IniRead(@ScriptDir& "\" & "ipconfig.ini",$affiche[$num_ip],"passerelle",""))
GUICtrlSetData($Input4_2,IniRead(@ScriptDir& "\" & "ipconfig.ini",$affiche[$num_ip],"dns",""))
EndFunc
Func affiche_ip_plus1()
$num_ip = $num_ip + 1
;if $num_ip > UBound($affiche)-1 Then $num_ip = 1
affiche_ip()
EndFunc
Func affiche_ip_moins1()
$num_ip = $num_ip - 1
;if $num_ip < 1 Then $num_ip = UBound($affiche)-1
affiche_ip()
EndFunc
Func nouvelle_config()
GUICtrlSetData($Input5_2,"")
GUICtrlSetData($Input1_2,"")
GUICtrlSetData($Input2_2,"")
GUICtrlSetData($Input3_2,"")
GUICtrlSetData($Input4_2,"")
EndFunc
Func enregistrer_config()
IniWrite(@ScriptDir& "\" & "ipconfig.ini",GUICtrlRead($Input5_2),"IPv4",GUICtrlRead($Input1_2))
IniWrite(@ScriptDir& "\" & "ipconfig.ini",GUICtrlRead($Input5_2),"masque",GUICtrlRead($Input2_2))
IniWrite(@ScriptDir& "\" & "ipconfig.ini",GUICtrlRead($Input5_2),"passerelle",GUICtrlRead($Input3_2))
IniWrite(@ScriptDir& "\" & "ipconfig.ini",GUICtrlRead($Input5_2),"dns",GUICtrlRead($Input4_2))
EndFunc
Func effacer_config()
IniDelete(@ScriptDir& "\" & "ipconfig.ini",GUICtrlRead($Input5_2))
;$affiche = IniReadSectionNames(@ScriptDir& "\" & "ipconfig.ini")
affiche_ip()
EndFunc
Func closed()
Exit
EndFunc
Func closed_gui_2()
GUISetState(@SW_HIDE,$Form2)
EndFunc




