Windows Batch File To Set Static IP Address Even if NIC is Renamed
Windows Batch File To Set Static IP Address Even if NIC is Renamed
My blog today is not specific to Cisco technologies, but it is something that I found useful in my Cisco classes. I needed a script that would set a static IP address on the network adapter, set a DNS server, and function even if the student had renamed the NIC. Here is the solution that worked for me.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | @ECHO OFF title {Whatever you want to have appear as the window title} :sn cd\ cls set /p sn=What is your student number (between 2 and 18)? Note, this script functions per student, but feel free to change your particulars REM **************Student number error trap************************** if %sn% lss 2 goto sn if %sn% gtr 18 goto sn REM ************************************************************* :choice echo You have entered that echo your student number is %sn%. set /p yn=If this is correct, type 'y' for yes or 'n' for no and hit Enter The following 4 lines prevents errors if the response is upper case vs lower case if %yn%==y goto set if %yn%==Y goto set if %yn%==n goto sn if %yn%==N goto sn cls echo Please select 'y' or 'n' goto choice :set cls echo Prepping your computer for the troubleshooting lab. Please wait... The timeout is not required, I just configured it so it looked busier timeout 5 for /f "skip=4 tokens=5*" %%i in ('netsh int ip show int') do echo %%i %%j> tmpvar In my case, the output I needed started at the fifth ‘chunk’, so my tokens started at 5. You can view the output of what I am parsing on your machine by typing netsh initerface ip show interface and locate the desired output set /p IN= < tmpvar netsh interface ipv4 set address name="%IN%" source=static 10.%sn%.10.100 mask=255.255.255.0 gateway=10.%sn%.10.10 netsh interface ipv4 set dnsservers "%IN%" static 8.8.8.8 primary > nul The ‘> nul’ guarantees nothing is sent to the screen so the student sees no output besides the ‘echo’ statements. echo Your computer is now ready for the lab pause exit |
Feel free to mod this script to meet your specific needs.
If you have any comments or questions, please feel free to post them….
Until next time.
Mark Jacob
Cisco and CompTIA Network + Instructor – Interface Technical Training
Phoenix, AZ
You May Also Like
Command prompt, DNS Server, NETSH, NIC, rename, script, static IP, tokens, variable
A Simple Introduction to Cisco CML2
0 3852 0Mark Jacob, Cisco Instructor, presents an introduction to Cisco Modeling Labs 2.0 or CML2.0, an upgrade to Cisco’s VIRL Personal Edition. Mark demonstrates Terminal Emulator access to console, as well as console access from within the CML2.0 product. Hello, I’m Mark Jacob, a Cisco Instructor and Network Instructor at Interface Technical Training. I’ve been using … Continue reading A Simple Introduction to Cisco CML2
Creating Dynamic DNS in Network Environments
0 626 1This content is from our CompTIA Network + Video Certification Training Course. Start training today! In this video, CompTIA Network + instructor Rick Trader teaches how to create Dynamic DNS zones in Network Environments. Video Transcription: Now that we’ve installed DNS, we’ve created our DNS zones, the next step is now, how do we produce those … Continue reading Creating Dynamic DNS in Network Environments
Cable Testers and How to Use them in Network Environments
0 713 1This content is from our CompTIA Network + Video Certification Training Course. Start training today! In this video, CompTIA Network + instructor Rick Trader demonstrates how to use cable testers in network environments. Let’s look at some tools that we can use to test our different cables in our environment. Cable Testers Properly Wired Connectivity … Continue reading Cable Testers and How to Use them in Network Environments