Announcement

Collapse
No announcement yet.

changing DHCP to Static IP address

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

  • changing DHCP to Static IP address

    Hello, I am trying to figure out how to write a script that allows me to read from a .txt file of all the computers I need to change there IP addresses.

    I have found this one and seems simple enough but when I try to run it I come into errors. I also would wonder if it can be written to read from a .txt file of the computer names
    Code:
    @echo off
    set wireless=
    echo Changes an IP address remotely. Will also setup subnet mask, default gateway, and DNS.
    echo.
    echo changeip [Current Host or IP] [New IP]
    echo.
    echo.
    echo.
    pause
    ping %2
    c:\tools\psexec -u username -p password \\%1 ipconfig /all
    echo.
    echo.
    echo.
    echo Entire Network Name:
    set /P wireless=
    echo on
    c:\tools\psexec -u username -p password \\%1 netsh interface ip set dns name="%wireless%" static 192.168.0.2
    c:\tools\psexec -u username -p password \\%1 netsh interface ip add dns name="%wireless%" 192.168.0.3 index=2
    c:\tools\psexec -u username -p password -d \\%1 netsh interface ip set address "%wireless%" static %2 255.255.255.0 192.168.0.1 1
    Thanks for any type of help

  • #2
    Re: changing DHCP to Static IP address

    Can you tell us what errors you get when you run it?
    (and the exact syntax you use)
    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: changing DHCP to Static IP address

      Yeah no problem,

      once run it asks "Press any key" after that is entered the ping command comes up with the options and states at the end "The system cannot find the path specified".

      the next line asks "Entire Network Name:" which I put in local area connection or wireless network connection.

      and it seems to run through it after that but with no change to the remote computer.

      here is what I input:
      Code:
      @echo off
      set wireless=
      echo Changes an IP address remotely. Will also setup subnet mask, default gateway, and DNS.
      echo.
      echo changeip [CART-2-011] [10.46.2.11]
      echo.
      echo.
      echo.
      pause
      ping %2
      c:\tools\psexec -u administrator -p "Long Strong Password" \\%1 ipconfig /all
      echo.
      echo.
      echo.
      echo Entire Network Name:
      set /P wireless=
      echo on
      c:\tools\psexec -u administrator -p "Long Strong Password" \\%1 netsh interface ip set dns name="%wireless%" static 192.168.0.2
      c:\tools\psexec -u administrator -p "Long Strong Password" \\%1 netsh interface ip add dns name="%wireless%" 192.168.0.3 index=2
      c:\tools\psexec -u administrator -p "Long Strong Password" -d \\%1 netsh interface ip set address "%wireless%" static %2 255.255.255.0 192.168.0.1 1
      I was hoping to know if anyone knows if it can look at a .txt file for the Host names to change IP addresses from that as well.

      Comment


      • #4
        Re: changing DHCP to Static IP address

        Sorry, I didn't mean to repost the script -- I meant the exact commands you type in (post a screenshot?)
        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


        • #5
          Re: changing DHCP to Static IP address





          Comment


          • #6
            Re: changing DHCP to Static IP address

            Why are you using psexec? Can't you use the -r switch to specify the remote machine?

            Comment


            • #7
              Re: changing DHCP to Static IP address

              Originally posted by grittyminder View Post
              Why are you using psexec? Can't you use the -r switch to specify the remote machine?
              I figure that psexec is the easiest way to complete the task I am trying to do. I just tried putting the @file into the mix which I just read about and its still not changing the host IP.

              Comment


              • #8
                Re: changing DHCP to Static IP address

                The batch (changeip.cmd) should be started with at leased two command line arguments (variables %1 and %2)! = these are the "current IP/Hostname" and the "new IP".

                The original batch and description is here http://countscomputercorner.blogspot...ely-using.html

                /Rems

                This posting is provided "AS IS" with no warranties, and confers no rights.

                __________________

                ** Remember to give credit where credit's due **
                and leave Reputation Points for meaningful posts

                Comment


                • #9
                  Re: changing DHCP to Static IP address

                  Originally posted by Rems View Post
                  The batch (changeip.cmd) should be started with at leased two command line arguments (variables %1 and %2)! = these are the "current IP/Hostname" and the "new IP".

                  The original batch and description is here http://countscomputercorner.blogspot...ely-using.html

                  /Rems
                  I understand that and that is where I found the original but for some reason this is not going through and for the life of me I can not figure it out. It seems very straight forward but unfortunately I seem to be a dummy.

                  Comment


                  • #10
                    Re: changing DHCP to Static IP address

                    How are you running the script -- you need to
                    a) open a command prompt
                    b) change to the script directory
                    c) type the name of the scripe plus the parameters (current IP/Name and New IP)

                    From the screen shots it looks as if you may be double clicking the script file?
                    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


                    • #11
                      Re: changing DHCP to Static IP address

                      Originally posted by Ossian View Post
                      How are you running the script -- you need to
                      a) open a command prompt
                      b) change to the script directory
                      c) type the name of the scripe plus the parameters (current IP/Name and New IP)

                      From the screen shots it looks as if you may be double clicking the script file?
                      OK, I think I finally got it going. You gave me the final kick to the head I needed.

                      I was double clicking, like a complete idiot. psexec was not running because in the original code its directing it to C:\tools but mine is C:\pstools. All is well now and I really appreciate all the help.

                      Comment

                      Working...
                      X