Announcement

Collapse
No announcement yet.

Batch Script For Static and DHCP

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch Script For Static and DHCP

    I need to switch between 2 diffrent networks, one gives out dhcp the other doesn't. I have tried over 10 scripts that i've gotten online, none of them work.


    ex.

    netsh interface ipv4 set address "Local Area Connection 2" static 10.1.10.46
    netsh interface ip add dns "Local Area Connection 2" 4.2.2.2 8.8.8.8


    ex.

    netsh interface ip set address name=”Local Area Network Connection” source=dhcp
    netsh interface ip set dns name=”Local Area Network Connection” source=dhcp register=primary
    netsh interface ip set wins name=”Local Area Network Connection” source=dhcp


    ex.

    netsh int ip set address name = "Local Area Connection 2" source = static addr = 10.1.10.74 mask = 255.255.255.0 gateway= 10.1.10.1


    Any Ideas?


    Thanks

  • #2
    Re: Batch Script For Static and DHCP

    Why not use "alternate configuration" on the computer (I assume it is only one) so it will pick up a static address if it doesn't get a DHCP one?
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: Batch Script For Static and DHCP

      i need to put this on several computers for people that are not computer savy. Someone told me to just use the batch, so i've just been rolling with that.

      Not sure what you mean by "alternate configuration"

      Comment


      • #4
        Re: Batch Script For Static and DHCP

        Try this, in two separate batch file scripts, or just copy/paste into elevated command prompt.


        rem Configure Static IP Address
        netsh interface ipv4 show interfaces
        netsh interface ipv4 set address name="Local Area Connection" source=static address=10.10.10.40 mask=255.255.0.0 gateway=10.10.10.1
        netsh interface ipv4 add dnsserver name="Local Area Connection" address=10.10.10.10 index=1
        Ipconfig /all

        rem Configure Dynamic IP Address
        netsh interface ipv4 set address name="Local Area Connection" source=dhcp
        netsh interface ipv4 set dnsservers name="Local Area Connection" source=dhcp
        ipconfig /all
        Last edited by uk_network; 25th September 2012, 21:05.
        Please remember to award reputation points if you have received good advice.
        I do tend to think 'outside the box' so others may not always share the same views.

        MCITP -W7,
        MCSA+Messaging, CCENT, ICND2 slowly getting around to.

        Comment


        • #5
          Re: Batch Script For Static and DHCP

          Originally posted by Kobe 310 View Post

          Not sure what you mean by "alternate configuration"
          http://support.microsoft.com/kb/283676

          Easier for users than a script, and can be configured using netsh if you need to
          Tom Jones
          MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
          PhD, MSc, FIAP, MIITT
          IT Trainer / Consultant
          Ossian Ltd
          Scotland

          ** Remember to give credit where credit is due and leave reputation points where appropriate **

          Comment


          • #6
            Re: Batch Script For Static and DHCP

            uk_Network

            That didn't work either, but at least i didn't get an error on your script. Thanks for the help though!!!


            Ossian

            It didn't have the Alternate Connection, but i got the point in the advance tab. Always wondered what that was for. Guess it was Self explanatory if i would've just experimented around with it. Duhhh!!!! Thanks for that, it is much easier!!!!!!



            Thanks Again!
            Last edited by Kobe 310; 26th September 2012, 14:08.

            Comment


            • #7
              Re: Batch Script For Static and DHCP

              Hi I tested on my computer before I posted it and worked perfectly.
              The default name for a network adapter is "Local Area Connection"
              If you have something different just edit the name to be Local Area Connection or what ever you have, Local Area Connection 2 or something. Just so it has the correct name of the connection you are trying to configure.
              Attached Files
              Last edited by uk_network; 26th September 2012, 22:40.
              Please remember to award reputation points if you have received good advice.
              I do tend to think 'outside the box' so others may not always share the same views.

              MCITP -W7,
              MCSA+Messaging, CCENT, ICND2 slowly getting around to.

              Comment


              • #8
                Re: Batch Script For Static and DHCP

                i did, i copied and pasted the local area connection, which is local area connection 2. My computer is already static, not sure if that would have something to do with it, i wouldn't think so.

                Comment

                Working...
                X