Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to add our new dhcp scope for around 2000 IPs, so I want any script for even apps that help me to do that, something that get my IP address from txt file and automatically insert and make my scope,

I heard that there is scripting to do this, Is there any script for doing this?

share|improve this question
2  
I think we're going to need much more information about what you're trying to do, your systems and what data you already have. –  Chopper3 Nov 30 '10 at 18:14
    
exactly for most of them I didn't get good answer, if it needed I can explain most of them, and I am sorry for my terrible English writing. –  user19049 Nov 30 '10 at 18:39
    
Really need more details on what your trying to do. Adding a single scope with 2000 IPs to a DHCP server is very simple to do manually. Adding 2000 scopes with various IP ranges is worthy of scripting... But I can't image why you would need 2000 scopes. –  Chris S Nov 30 '10 at 18:42
    
yes I want to add 150 scope with their options in DCHP, I want to automatic this adding scope, because I have to add these scope on 300 switches too. –  user19049 Nov 30 '10 at 18:46
    
What kind of dhcp server are you using? Windows, *nix, dedicated hardware (eg managed switch)? –  Chris S Nov 30 '10 at 18:48

2 Answers 2

up vote 1 down vote accepted

Use Powershell. You'll want to look at the ".." range operator, and have a look at the Net-SubnetMath.ps1 functions by Chris Dent.

Your goal is to have PowerShell output a batch file with the needed netsh.exe commands; here's an example to create 3 host reservations:

netsh dhcp server \\DC scope 10.0.0.0 add reservedip 10.1.1.1 1234567890ab hostname1
netsh dhcp server \\DC scope 10.0.0.0 add reservedip 10.1.1.2 1234567890ac hostname2
netsh dhcp server \\DC scope 10.0.0.0 add reservedip 10.1.1.3 1234567890ad hostname3

The Net-SubnetMath functions are useful for calculating IP address lists when you need something more than just a +1 increment. Here's an example where I needed to calculate a list of IPV4 addresses that incremented by 32:

Take your starting IP address, call the ConvertTo-DecimalIP function, and stuff it in the variable $a :

$a = ConvertTo-decimalIP 10.128.42.125

Then, loop adding 32 to the address each time. Write the output as dotted decimal:

for ($i=0; $i -lt 512; $i+=32) {ConvertTo-DottedDecimalIP ($a + $i)}

10.128.42.125
10.128.42.157
10.128.42.189
...

You can use this technique to very rapidly create the framework of DHCP scopes, and to insert whatever options are appropriate for that scope; just loop it as many times as you need.

share|improve this answer
    
Thanks I used this technique, but I couldn't set classless static route with 249 value! what is the Classless static route command? –  user19049 Dec 1 '10 at 9:34
    
Sorry, I don't know the classless static route command, but I'm happy the rest helped. –  AndyN Dec 1 '10 at 17:26

Your question isn't particularly clear. However, if your using Win2k3/Win2k8, you can script DHCP with NETSH.EXE. If you can clarify exactly what you're trying to do, I can provide an example.

share|improve this answer
    
We have Windows Server 2003 R2, with about 2000 Client, We are using 16-bit subnet mask, and around 120 DHCP Scope. We want to change our scope to new 150 scope and change the IP range address, so we want using script to automatic these 150 DHCP scope and options. Is there any script? please give me an example –  user19049 Nov 30 '10 at 18:43
    
I am looking for something like this phishthis.com/2010/06/18/…;, but this is a little bit complicated. –  user19049 Nov 30 '10 at 18:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.