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
Agile Methodology in Project Management
0 163 0In this video, you will gain an understanding of Agile and Scrum Master Certification terminologies and concepts to help you make better decisions in your Project Management capabilities. Whether you’re a developer looking to obtain an Agile or Scrum Master Certification, or you’re a Project Manager/Product Owner who is attempting to get your product or … Continue reading Agile Methodology in Project Management
Creating Users and Managing Passwords in Microsoft Office 365
0 706 3In this Office 365 training video, instructor Spike Xavier demonstrates how to create users and manage passwords in Office 365. For instructor-led Office 365 training classes, see our course schedulle: Spike Xavier SharePoint Instructor – Interface Technical Training Phoenix, AZ 20347: Enabling and Managing Office 365
JavaScript for C# Developers – September 24, 2014
0 494 3Is JavaScript worth taking the time to learn if I’m a server-side .NET developer? How much of C# carries over to JavaScript? In this recorded video from Dan Wahlin’s webinar on September 24,2014, Dan answers these questions and more while also discussing similarities between the languages, key differences, and the future of JavaScript (ES6). If … Continue reading JavaScript for C# Developers – September 24, 2014