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.