Change IP Config Using Simple Batch Script

I have a two laptops and only one network port, although i can use wifi on both computers, I prefer to use cable whenever I can for faster internet speed. So when sharing internet through one laptop to the other i need to switch IP config settings, which is a pain (where I need to change IP address, subnet and default gateway in IPV4, local area connection adapter).

Therefore I came up with this simple script for easier access to the IP config settings. There are two main things it can do: 1. set static IP address; 2. set auto IP config (dhcp – dynamic ip address).

@echo off 
echo Notice: Make sure you are running this script as Admin, Otherwise it won't work! (right click on the script, click "Run As Administrator")
echo Choose: 
echo [A] Set Static IP 
echo [B] Set DHCP 
echo. 
:choice 
SET /P C=[A,B]? 
for %%? in (A) do if /I "%C%"=="%%?" goto A 
for %%? in (B) do if /I "%C%"=="%%?" goto B 
goto choice 

:A 
@echo off 
echo "Please enter Static IP Address Information" 
echo "Static IP Address:" 
set /p IP_Addr=

echo "Subnet Mask:" 
set /p Sub_Mask=

echo "Default Gateway:" 
set /p D_Gate=

echo "Setting Static IP Information" 
netsh interface ip set address name="Local Area Connection" static %IP_Addr% %Sub_Mask% %D_Gate%
netsh int ip show config 
pause 
goto end

:B 
@ECHO OFF 
ECHO Resetting IP Address and Subnet Mask For DHCP 
netsh int ip set address name = "Local Area Connection" source = dhcp

ipconfig /renew

ECHO Here are the new settings for %computername%: 
netsh int ip show config

pause 
goto end 

:end

Don’t forget you have to run this script as Administrator, otherwise it won’t work.

4 thoughts on “Change IP Config Using Simple Batch Script

      1. Bryan Ringrose

        Could you be more arrogant!?
        The code is not that elegant and has been passed on from site to site. Yes this is a very useful script that someone has posted on a knowledge sharing website so IT IS OK (without being perceived as lazy) to ask about DNS just like others have asked on this very script. Please do ask questions, rude comments are not needed.

  1. Jaimie

    Nice post. I was checking continuously this blog
    and I am impressed! Very useful info specially
    the last part :) I care for such info much. I was
    seeking this particular information for a long time.
    Thank you and best of luck.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you Robot? *

For prompt technical support, please use our forum IntoFPV.com. I check blog comments weekly.