Set your IP address via a batch file that you can call via a double click.
You all know that I love the Command Prompt and creating fanciness through Batch Files – and here’s a good one for you: Set your IP address via a batch file!
You all know that I love the Command Prompt and creating fanciness through Batch Files – and here’s a good one for you: Set your IP address via a batch file!
This command will work in both Windows XP and Windows Vista
The code:
Now, I realize that it looks like there is a lot going on there but
there really isn’t. The way I have written the code, the user will not
see all of the coding when the batch file is run, but they will see
feedback as to what is going on. Also, you don’t really have to declare
all of the variables first, you could just pass them directly from that
line. Example:
But, I created this so that you (or whoever you give this to) wont
have to go searching through the code if the variables need to be
changed – plus, it’s better programing practice to declare your
variables first!
Why Should I Bother?
This can be useful for a few reasons:- You use DHCP at home and a Static IP at work (assuming you transport your laptop)
- You need to set the IP address for multiple computers
- You are in a hotel
- etc
How To
I’ll first post the code, then I’ll explain what’s going on.The code:
- @ECHO OFF
- set varip=65.88.48.77
- set varsm=255.255.255.224
- set vargw=65.88.48.65
- set vardns1=66.78.202.254
- set vardns2=66.78.210.254
- set varhome=www.google.com
- REM ***** You don’t need to change anything below this line! ******
- ECHO This fanciness is brought to you by Saman Sadeghi!
- ECHO Setting IP Address and Subnet Mask
- netsh int ip set address name = "Local Area Connection" source = static addr = %varip% mask = %varsm%
- ECHO Setting Gateway
- netsh int ip set address name = "Local Area Connection" gateway = %vargw% gwmetric = 1
- ECHO Setting Primary DNS
- netsh int ip set dns name = "Local Area Connection" source = static addr = %vardns1%
- ECHO Setting Secondary DNS
- netsh int ip add dns name = "Local Area Connection" addr = %vardns2%
- ECHO Setting Internet Explorer Homepage to %varhome%
- reg add "hkcusoftwaremicrosoftinternet explorermain" /v "Start Page" /d "%varhome%" /f
- ECHO Here are the new settings for %computername%:
- netsh int ip show config
- pause
-
netsh int ip set address name = "Local Area Connection" source = static addr = 65.88.48.77 mask = 255.255.255.224
No comments:
Post a Comment