Bindgen Source Code
To save, select all text below the divider, paste into any text editor, and save as 'bindgen-a.php'
<!--
©2007 Dan Lapoint / The Opentastic Group.
This work is protected by the terms of the GNU General Public License (GPL): http://www.gnu.org/copyleft/gpl.html
================================================================================================
Notes:
This script was developed and tested with PHP 5.2.4 on Windows 2003/Apache 2.2.4 and PHP 5.2.1 on Debian Linux/Apache 2.2.3. I make no guarantee that it will work on either. It works for me, but your configuration may be different. If this script does not work for you, you may contact me, and I'll try to help, but please remember that you did not pay for this software, so I'm not really obligated to support it. If you don't like it, or it doesn't work on your machines, write your own program :)
This is a script that I wrote to solve a problem I had. I thought it might be useful to someone else, so I decided to make it available on the Internet. That's all. I'm not trying to become the next Microsoft. I'm not trying to write the greatest script ever. I had a problem that needed solving, it's that simple. I hope this script can also solve your problem, but I certainly do not warrant that it will.
-->
<html>
<head>
<title>BIND DHCP Range Tool<?php if ( isset($_GET['op']) ) { echo ': ' . $_GET['net'] . '.' . $_GET['min'] . ' - ' . $_GET['net'] . '.' . $_GET['max']; } ?></title></head>
<style>
body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #000 }
</style>
</head>
<body>
<div style="width: 1060px"><p>This is just a simple tool that takes your network information, and generates BIND zone entries. This tool is designed to create forward and reverse records for your DHCP range.</p>
<p>For example, if you wanted to name all of the dynamic-IP clients in your network "dhcp-###.office.corporate.com", where "###" is the C-block of each IP address, this tool allows you to generate the BIND records for that, both A and PTR.</p></div>
<?php
$min = $_GET['min'];
$max = $_GET['max'];
$net = $_GET['net'];
$pfx = $_GET['pfx'];
$hst = $_GET['hst'];
$arp = $s = implode('.', array_reverse(explode('.', $net)));
$ipck = $net;
$ipck .= ".1";
if ( isset($min) && !in_array($min, range(1, 254)) ) { die('<p style="color: red"><img src="error.png" alt="error" style="vertical-align: middle" /> The beginning of your DHCP range, "' . $net . '.' . $min . '", is an invalid IP address. All addresses must be between ' . $net . '.1 and ' . $net . '.254.</p></body></html>'); }
if ( isset($max) && !in_array($max, range(1, 254)) ) { die('<p style="color: red"><img src="error.png" alt="error" style="vertical-align: middle" /> The end of your DHCP range, "' . $net . '.' . $max . '", is an invalid IP address. All addresses must be between ' . $net . '.1 and ' . $net . '.254.</p></body></html>'); }
?>
<div style="float: left">A records:
<div style="border: 1px solid #F00; width: 480px; height: 480px; overflow: scroll; font-family: 'Courier New', Courier, monospace; font-size: 11px; margin: 2px; padding: 2px; text-align: center">
<?php if ( isset($_GET['op']) ) {
foreach (range($min, $max) as $host) { ?>
<?php echo $pfx; ?><?php echo $host; ?>.<?php echo $hst; ?>. IN A <?php echo $net; ?>.<?php echo $host; ?><?php echo "<br />"; ?>
<?php } } else { echo 'Please enter your DHCP and network info below.'; } ?></div></div>
<div>PTR Records:
<div style="border: 1px solid #F00; width: 580px; height: 480px; overflow: scroll; font-family: 'Courier New', Courier, monospace; font-size: 11px; margin: 2px; padding: 2px; text-align: center">
<?php if ( isset($_GET['op']) ) {
foreach (range($min, $max) as $host) { ?>
<?php echo $host; ?>.<?php echo $arp; ?>.in-addr.arpa. IN PTR <?php echo $pfx; ?><?php echo $host; ?>.<?php echo $hst; ?>.
<?php echo "<br />"; } } else { echo 'Please enter your DHCP and network info below.'; } ?>
</div></div>
<form action="bindgen-a.php" method="get">
<p>Note: this only works with class "C" nets (/24)</p>
<input type="hidden" name="op" value="ds" />
<p>Network: <input type="text" name="net" style="width: 100px" value="<?php if ( isset($net) ) { echo $net; } ?>" /> ("10.20.30" if your network is 10.20.30.0/24)</p>
<p>Network domain: <input type="text" name="hst" style="width: 150px" value="<?php if ( isset($hst) ) { echo $hst; } ?>" /> (e.g. example.corporate.com)</p>
<p>DHCP host naming prefix: <input type="text" name="pfx" style="width: 100px" value="<?php if ( isset($pfx) ) { echo $pfx; } ?>" /> (If you want dyn-123.example.corporate.com, put "dyn-")</p>
<p>DHCP IP range: <input type="text" name="min" style="width: 30px" value="<?php if ( isset($min) ) { echo $min; } ?>" /> to <input type="text" name="max" style="width: 30px" value="<?php if ( isset($max) ) { echo $max; } ?>" /></p>
<p><input type="submit" value="Generate Records" /> </p>
</form>
</body>
</html>