+ Post New Thread
Results 1 to 3 of 3
Scripts Thread, IP Address changer help in Coding and Web Development; Hi all, We are in the process of changing our subnet mask, in order to bring in a new network ...
  1. #1

    Join Date
    Jan 2009
    Location
    Weston Super Mare
    Posts
    66
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    13

    IP Address changer help

    Hi all,

    We are in the process of changing our subnet mask, in order to bring in a new network range onto the site.

    I have written a script that changes only the subnet mask, but i have come to a problem. Most of the clients are on static ip address because of some of the software that we run. Some are on DHCP.

    In the script i want to exclude it from changing any ip addresses that are assigned by DHCP, as at the moment it takes the DHCP assigned address, and turns it into a static one!

    Any help would be much appreciated?

    Code below ------------------------

    strComputer = "LocalHost"
    strUser = "VOSPERS\Administrator"
    strPassword = ""
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


    Set colNetAdapters = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

    strSubnetMask = Array("255.255.254.0")




    For Each objNetAdapter in colNetAdapters
    strIPAddress = objNetAdapter.IPAddress
    strGateway = objNetAdapter.DefaultIPGateway
    strGatewayMetric = objNetAdapter.GateWayCostMetric

    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
    errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    If errEnable = 0 Then
    WScript.Echo "The IP address has been changed."
    Else
    WScript.Echo "The IP address has been changed."
    End If
    Next
    Last edited by gream0604; 8th February 2011 at 10:53 AM.

  2. #2
    CJF
    CJF is offline

    CJF's Avatar
    Join Date
    Aug 2010
    Location
    Leeds, UK
    Posts
    262
    Thank Post
    27
    Thanked 89 Times in 70 Posts
    Rep Power
    23
    Hi Gream0604,

    Why don't you use static leases in your dhcp pool? I'm guessing you already know which have static addresses at the moment, just get their mac addresses and hand out their reservations in dhcp.

    Also, I hope that isn't your actual admin password in your script

  3. #3

    Join Date
    Jan 2009
    Location
    Weston Super Mare
    Posts
    66
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    13
    Hi CJF,

    Whoops. I have removed it now!!

    I have sorted it now. The new script reads:

    --------------------------------------------------------

    strComputer = "LocalHost"
    strUser = "VOSPERS\Administrator"
    strPassword = "password"
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")



    Set colNetAdapters = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

    strSubnetMask = Array("255.255.254.0")


    For Each objNetAdapter in colNetAdapters

    If objnetadapter.DHCPEnabled = True Then

    wscript.quit

    else
    strIPAddress = objNetAdapter.IPAddress
    strGateway = objNetAdapter.DefaultIPGateway
    strGatewayMetric = objNetAdapter.GateWayCostMetric

    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
    errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    If errEnable = 0 Then
    WScript.Echo "The IP address has been changed."
    Else
    WScript.Echo "The IP address has been changed."
    End If

    End If



SHARE:
+ Post New Thread

Similar Threads

  1. Netbook Screen Resolution Changer
    By SimpleSi in forum Windows
    Replies: 23
    Last Post: 23rd November 2012, 06:42 PM
  2. [Fog] hostname changer issues
    By stevehp in forum O/S Deployment
    Replies: 1
    Last Post: 9th July 2010, 09:01 PM
  3. Powertools Wallpaper Changer
    By Hightower in forum Windows
    Replies: 1
    Last Post: 19th March 2010, 11:11 AM
  4. MEGA HELP! ZlobDNS Changer
    By rolfea in forum How do you do....it?
    Replies: 2
    Last Post: 29th January 2009, 01:24 PM
  5. Proxy Changer Script
    By plexer in forum Scripts
    Replies: 19
    Last Post: 12th March 2008, 04:20 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •