CISCO DHCP IP routes option 249 / 121 configurator / generator / script

If You need to add option 249 to Your cisco dhcp, and need to announce network with mask bigger tnah /24 ( fg. /16 /8 ) use this script:

#!/usr/bin/perl -w
 use strict;
 sub option_121 {
 my $gw = shift;
 my $out_str = '';
 my ($subnet, $mask, $b0, $b1, $b2, $b3);
 foreach my $cidr (@_) {
 ($subnet, $mask) = split('/', $cidr);
 ($b0, $b1, $b2, $b3) = split(/\./,$subnet);
 $out_str .= sprintf('%02x', $mask);
 $out_str .= sprintf('%02x', $b0);
 $out_str .= sprintf('%02x', $b1) if($mask > 8);
 $out_str .= sprintf('%02x', $b2)
 if($mask > 16);
 $out_str .= sprintf('%02x', $b3) if($mask > 24);
 $out_str .= sprintf('%02x%02x%02x%02x', split(/\./,$gw));
 }
 return $out_str;
 }
 if(@ARGV < 2)
 {
 print "Usage: $0 GW-IP Subnet1/Mask1 Subnet2/Mask2 ... SubnetXX/maskXX\n";
 }
 elsif($ARGV[0] =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)
 {
 print "DHCP option 249 hex string: ".option_121(@ARGV)."\n";
 }
 
Usage: 
./routes-to-hex.pl 172.22.1.1 172.20.1.0/24 172.20.2.0/24 172.21.0.0/16
 DHCP option 249 hex string: 18ac1401ac16010118ac1402ac16010110ac15ac160101

At router:

ip dhcp pool PPTP
network 172.22.1.0 255.255.255.0
domain-name domain.com.pl
dns-server 172.20.1.3 172.20.1.6
option 249 hex 18ac.1401.ac16.0101.18ac.1402.ac16.0101.10ac.15ac.1601.01
default-router 172.22.1.1

Done! 🙂