# .bat file to set static ip



## G-Stress (Feb 4, 2008)

Hey guys, a little confused here. I run 2 networks in my home one with no dhcp and one with dhcp. I often switch between the 2, but when doing so I have to goto the network connection and enter in the static ip or switch it back to dhcp. So what I'm trying to do is create a .bat file that will do it all for me.

I've created .bat files to set it to static and to dhcp, problem is I want the .bat file to ask me which connection I want to set static and then ask me to enter in the ip, dns, netmask and gateway. So..


```
rem TCP/IP Configuration

:start

echo 1. Set Static IP
echo 2. Set IP to DHCP
echo 3. Set Static DNS 
echo 4. Set Auto DNS

set /p input= "Enter Option Here: "

if "%input%"=="1"      goto:staticip
if "%input%"=="2"      goto:dhcp
if "%input%"=="3"      goto:staticdns
if "%input%"=="4"      goto:autodns

:staticip

set /p static="Enter IP, Netmask & Gateway"

netsh interface ip set address local static "%static%"
goto:start

:dhcp

netsh interface ip set address name=Local Area Network Connection source=dhcp
goto:start
```
The auto part is pretty easy. I'm not a coder by any means. The hard part is I'm not sure how to tell it to ask me which adapter I want to set static or auto and then ask me what IP, dns, gw, mask I want to use. When I tried the above I got an error that the value was improper or something for addr.

Any help or advice is greatly appreciated.


----------



## Squashman (Apr 4, 2003)

I personally would ditch the batch file and use this.
http://www.snapfiles.com/get/netsetman.html


----------



## G-Stress (Feb 4, 2008)

@Squashman, ahhhh that is perfect  This is actually even better. I will leave this open in case anyone wants to share how to do this via .bat for my own personal knowledge, but this utility will work perfectly for my needs.

Thanks again.


----------



## Squashman (Apr 4, 2003)

I used NetSetMan when I worked for the school district. I had one tab setup for DHCP and the other tab set for a static IP address. I had to be on a specific static IP address to bypass the proxy server.


----------

