Salut,
Je suis à la recherche d'une fonction ou procédure qui permettrait de changer l'adresse ip, la passerelle, le dns,... Sur une machine locale...
Pourriez-vous m'aider?
Salut,
Je suis à la recherche d'une fonction ou procédure qui permettrait de changer l'adresse ip, la passerelle, le dns,... Sur une machine locale...
Pourriez-vous m'aider?
Pourquoi vouloir ré-inventer la roue...
...Surtout si c'est pour la faire carrée...
moi je fais ca en utilisant la fonction netsh de windows (sous dos)
ca donne :
avec :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 If CheckDHCP.Checked Then Begin cde := 'netsh interface ip set address "'+ conn +'" source=dhcp'; execute_dos(cde); cde := 'netsh interface ip set dns "'+ conn +'" source=dhcp'; execute_dos(cde); cde := 'netsh interface ip set wins "'+ conn +'" source=dhcp'; execute_dos(cde); End Else Begin cde := 'netsh interface ip set address "'+ conn +'" static ' + EditIp.Text + ' ' + EditMask.Text; if EditGateway.Text <> '' then cde := cde + ' ' + EditGateway.Text + ' 1'; execute_dos(cde); cde := 'netsh interface ip set win "'+ conn +'" static ' + EditPWS.Text; execute_dos(cde); End;
j'utilise :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 procedure execute_dos(CommandeDos : string); var StartInfo : TStartupInfo; ProcessInformation : TProcessInformation; begin ZeroMemory(@StartInfo, sizeof(StartInfo)); // remplie de 0 StartInfo StartInfo.cb:=sizeof(StartInfo); StartInfo.dwFlags:=STARTF_USESHOWWINDOW; StartInfo.wShowWindow:=SW_HIDE; if CreateProcess(nil,PChar(CommandeDos),nil,nil,true,0,nil,nil,StartInfo,ProcessInformation) then WaitForSingleObject(ProcessInformation.hProcess, INFINITE); end;
CONN : nom de la connection reseau (par defaut ss xp : Connexion au réseau local)
j'espere que cela t'aidera.
Et dans ce cas on est sur qu'il n'y a pas d'effet de bord.Envoyé par firejocker
Mais netsh est-il spécifique à une plateforme, sous XP d'accord mais sous NT ?
WMI peut être aussi une solution si tu ne souhaites pas utiliser les API.
Exemple de script WSH, adaptable sous Delphi, pour modier l'adresse IP et la gateway:
ou encore, pour modifier le domain DNS.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colNetAdapters = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") strIPAddress = Array("192.168.1.141") strSubnetMask = Array("255.255.255.0") strGateway = Array("192.168.1.100") strGatewayMetric = Array(1) For Each objNetAdapter in colNetAdapters errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) If errEnable = 0 Then WScript.Echo "The IP address has been changed." Else WScript.Echo "The IP address could not be changed." End If Next
...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 On Error Resume Next strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colNetCards = objWMIService.ExecQuery _ ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") For Each objNetCard in colNetCards Wscript.Echo objNetCard.SetDNSDomain("fabrikam.com") Next
Tutoriels Delphi Win32/Delphi .NET/Oracle/PowerShell - FAQ Delphi - FAQ Delphi .NET
Beatus, qui prodest, quibus potest.
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager