Netwerkadapter instellingen wijzigen d.m.v CMD.

NigelHagen

Windows Geek
#1
(LET OP: VERVANG DE address name door jouw netwerkadapter)

Je kan je IP adres, Subnetmask, Gateway en DNS instellen via de command prompt. En dus ook via een batchfile. Handig voor als je via een script een systeem uitrolt of anderzijds je IP adres wilt kunnen wijzigen via de prompt. Je kan vaste gegevens invoeren of instellen op DHCP.

Dit doe je met het commando: netsh.exe

Usage: netsh [-a AliasFile] [-c Context] [-r RemoteMachine] [-u [DomainName\]UserName] [-p Password | *]
[Command | -f ScriptFile]
The following commands are available:
Commands in this context:
? – Displays a list of commands.
aaaa – Changes to the `netsh aaaa’ context.
add – Adds a configuration entry to a list of entries.
bridge – Changes to the `netsh bridge’ context.
delete – Deletes a configuration entry from a list of entries.
dhcp – Changes to the `netsh dhcp’ context.
diag – Changes to the `netsh diag’ context.
dump – Displays a configuration script.
exec – Runs a script file.
firewall – Changes to the `netsh firewall’ context.
help – Displays a list of commands.
interface – Changes to the `netsh interface’ context.
ipsec – Changes to the `netsh ipsec’ context.
ras – Changes to the `netsh ras’ context.
routing – Changes to the `netsh routing’ context.
rpc – Changes to the `netsh rpc’ context.
set – Updates configuration settings.
show – Displays information.
wins – Changes to the `netsh wins’ context.
winsock – Changes to the `netsh winsock’ context.
The following sub-contexts are available:
aaaa bridge dhcp diag firewall interface ipsec ras routing rpc wins winsock
To view help for a command, type the command, followed by a space, and then type ?.
IP en Subnetmask

netsh interface ip set address name=”Local Area Connection” source=static addr=192.168.1.150 mask=255.255.255.0
Gateway

netsh interface ip set address name=”Local Area Connection” gateway=192.168.1.1 gwmetric=1
DNS (eerste en tweede)

netsh interface ip set dns name=”Local Area Connection” source=static addr=192.168.1.5
netsh interface ip add dns name=”Local Area Connection” addr=192.168.1.6
WINS (eerste en tweede)

netsh interface ip set wins name=”Local Area Connection” source=static addr=192.168.1.21
netsh interface ip add wins name=”Local Area Connection” addr=192.168.1.22
Bovenstaande IP adressen zijn uiteraard fictief en dien je te vervangen voor je eigen waarden.

Alles op DHCP zetten (IP, DNS en WINS)

netsh interface ip set address name=”Local Area Connection” source=dhcp
netsh interface ip set dns name=”Local Area Connection” source=dhcp
netsh interface ip set wins name=”Local Area Connection” source=dhcp
Batchfile

Stel dat we dit nu in een batch file willen gieten dan kun je op de volgende manier iets moois maken waarbij ook alles meteen variabel is.

@echo off
setlocal
cls
rem ** define variables **
set MYADAPTERNAME=”Local Area Connection”
set MYIP=192.168.1.150
set MYSUBNETMASK=255.255.255.0
set MYGATEWAY=192.168.1.1
set MYDNS1=192.168.1.5
set MYDNS2=192.168.1.6
rem ** apply new settings **
netsh interface ip set address name=%MYADAPTERNAME% source=static addr=%MYIP% mask=%MYSUBNETMASK%
netsh interface ip set address name=%MYADAPTERNAME% gateway=%MYGATEWAY% gwmetric=1
netsh interface ip set dns name=%MYADAPTERNAME% source=static addr=%MYDNS1%
netsh interface ip add dns name=%MYADAPTERNAME% addr=%MYDNS2%


Source: http://www.viperlook.com/2010/06/ip-adres-instellen-met-een-batchfile/
 

Nieuwste berichten

Bovenaan Onderaan