+ Post New Thread
Results 1 to 5 of 5
Windows Thread, Is there a way of creatin DHCP reservations from a CSV file? in Technical; Does anyone know of a way that I can create all of my DHCP reservations from a CSV file? :? ...
  1. #1
    Gonk's Avatar
    Join Date
    Aug 2007
    Location
    Haverfordwest, Pembrokeshire
    Posts
    536
    Thank Post
    124
    Thanked 100 Times in 73 Posts
    Rep Power
    71

    Is there a way of creatin DHCP reservations from a CSV file?

    Does anyone know of a way that I can create all of my DHCP reservations from a CSV file? :?

    It would really help as I'm trying to put this network in order and get some order.

    Thanks in advance

    Gonk

  2. #2
    Iain's Avatar
    Join Date
    Oct 2006
    Location
    Warwickshire
    Posts
    188
    Thank Post
    28
    Thanked 93 Times in 53 Posts
    Rep Power
    32

    Re: Is there a way of creatin DHCP reservations from a CSV f

    I don't think you can do this from the GUI, but you should be able to with a bit of scripting. e.g. using vbscript and the NETSH command:

    Code:
    ' script to bulk create DHCP reservations from a .csv file
    
    ' Set a couple of constants
    ' Set following line to IP address of DHCP server, or leave blank for local computer
    Const DHCPServer = "" 
    ' Set following line to address scope where reservation is to be added
    Const SCOPE = "192.168.1.0" 
    ' Set following line to location of .csv file containing the reservation to be added
    Const FileLocation = "C:\reservations.csv" 
    
    ' read in the csv file
    ' format:
    ' <Reserved IP>,<MAC>,<Client Name>,<Description>
    
    Const forReading = 1
    
    Set objShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objCSVFile = objFSO.OpenTextFile(FileLocation,forReading)
    
    ' Process csv file
    Do While objCSVFile.AtEndOfStream <> True
    	' read in a line from the csv file
    	strLine = objCSVFile.ReadLine
    
    	' seperate the cells on the line
    	arrCells = split(strLine,",",-1,1)
    
    	' get the values from the cells
    	strIP = arrCells(0)
    	strMAC = arrCells(1)
    	strClientName = arrCells(2)
    	strDescription = arrCells(3)
    
    	' build the NETSH command string
    	strCmd = "netsh dhcp server " & DHCPServer & " scope " & SCOPE & " add reservedip " & _
                  strIP & " " & strMAC & " " & strClientName & " """ & strDescription & """"
    
    	' run the NETSH command
    	objShell.Run strCmd, 1, TRUE
    Loop
    
    ' All done so close the csv file
    objCSVFile.close
    
    ' Clean up objects
    Set objCSVFile = Nothing
    Set objFSO = Nothing
    Set objShell = Nothing
    
    WScript.Echo "All done."
    I have not fully tested this, so as always make a backup before using it.

    Hope that is of some help,

    Iain.

  3. #3
    Heebeejeebee's Avatar
    Join Date
    Nov 2006
    Location
    Intergalactic Cruise
    Posts
    1,056
    Thank Post
    69
    Thanked 77 Times in 61 Posts
    Rep Power
    35

    Re: Is there a way of creatin DHCP reservations from a CSV file?

    Use...

    netsh dhcp server \\servername dump >c:\dhcp.txt

    ... to get your current list. Look for the reservation section:

    Code:
        
       # ======================================================================
       #  Start Add ReservedIp to the Scope : IP of Server Server : IP of Server            
       # ======================================================================
    
    
    Dhcp Server SERVER-IP Scope SCOPE-IP Add reservedip RESERVEVED-IP MAC-ADDRESS "SomePC" "Description" "BOTH"
    and paste in your own list (from your spreadsheet).

    then import the amended file with

    netsh exec c:\dhcp.txt

    Works a treat for us.

    HBJB

  4. 3 Thanks to Heebeejeebee:

    BaronVonSchtuk (6th March 2011), Gonk (6th February 2009), simpsonj (1st October 2012)

  5. #4
    Gonk's Avatar
    Join Date
    Aug 2007
    Location
    Haverfordwest, Pembrokeshire
    Posts
    536
    Thank Post
    124
    Thanked 100 Times in 73 Posts
    Rep Power
    71

    Re: Is there a way of creatin DHCP reservations from a CSV f

    @Heebeejeebee & Iain

    Gents,

    Thanks for your help, DHCP now a lot more organised!

    Thanks for your help

    Gonk

  6. #5
    mrtass's Avatar
    Join Date
    Apr 2009
    Posts
    1
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    DHCP Scope export tool

    you can use this small tool to generate scopes for your DHCP
    then use the DHCP import tool as described by [Heebeejeebee]

    goodluck
    Attached Files Attached Files

SHARE:
+ Post New Thread

Similar Threads

  1. Access points not picking up DHCP reservations?
    By Halfmad in forum Wireless Networks
    Replies: 2
    Last Post: 26th April 2007, 02:11 PM
  2. Replies: 3
    Last Post: 24th January 2007, 11:11 PM
  3. Replies: 4
    Last Post: 23rd March 2006, 06:27 AM
  4. VPN +DHCP
    By Dos_Box in forum Wireless Networks
    Replies: 7
    Last Post: 30th September 2005, 01:14 AM
  5. DHCP
    By kingswood in forum Wireless Networks
    Replies: 10
    Last Post: 7th September 2005, 06:29 AM

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
  •