I use my personal laptop at work and at home. To access the network, I have to change network settings twice a day. Moreover, both at home and in the office there is a binding to the MAC address of the machine. Therefore, it is also necessary to change the MAC in the properties of the network card.
To somehow automate this process, a command line and a search engine were launched. Details and the finished bat-file under the cut.
Introduction
To change the IP in the windows command line there is the netsh utility. More on what it is and why it is eaten on the
wiki .
To change the MAC address, I did not find the standard tools (if there are any, please indicate, I will be grateful). Therefore, I used the program Macshift. You can download
from the official site .
Classes bat-anika
Create a network.bat file with the contents:
@echo off
set /p mesto=" (1 - , 2 - ): "
echo - %mesto%
if %mesto% equ 2 goto rabota
:dom
set IFACE="local"
set IP=10.160.100.9
set MASK=255.255.255.0
set GATEWAY=10.160.100.1
set GWMETRIC=1
set DNS1=10.160.100.1
set MAC=001122334455
goto smena
:rabota
set IFACE="local"
set IP=192.168.1.91
set MASK=255.255.255.0
set GATEWAY=192.168.1.1
set GWMETRIC=1
set DNS1=192.168.1.10
set MAC=221133004455
goto smena
:smena
echo MAC %MAC%
echo _____
macshift -i "local" %MAC%
echo _____
echo IP -%IP%
echo -%MASK%
echo -%GATEWAY%
netsh interface ip set address name=%IFACE% source=static addr=%IP% mask=%MASK% gateway=%GATEWAY% gwmetric=%GWMETRIC%
echo DNS %DNS1%
netsh interface ip set dns name=%IFACE% source=static addr=%DNS1% register=PRIMARY
echo :
ipconfig /all
echo _____
pause
Pay attention to the beginning of the file, after the
dom and
rabota labels we enter our settings.
Note: "echo _____" is used exclusively from aesthetic beginnings.Last preparations
I placed the macshift program and batch file in d: \ program \ network. And on the desktop made the label network.lnk. When launching a shortcut, the batch file starts with the question of choosing settings. Pressing "1", we get the settings for the house, respectively, "2" - for the office.
Maybe someone this topic will be useful.