Gheek.net

January 27, 2008

vlanrangeset_cgi

Filed under: cgi, Cisco, perl — Tags: , , , — lancevermilion @ 11:38 pm
#!/usr/bin/perl
#Author: Lance Vermilion
#Description: Create a list of vlans in a range format "1,3-300,302-999"
#                 to be set to on trunk ports.
################################################


use strict;
use warnings;
use CGI qw(:standard);

sub usage () {
print
  "Content-type: text/html\n\n" .
  "\n\n" .
  "Vlan Range Results\n" .
  "\n" .
  "\n" .
  "

ERROR

\n" . "

\n" . "\n"; print "\nYOU MUST FILL OUT EVERY FIELD\n"; print "\n" . "\n\n"; exit 0; } #### # Question for the user #### my $numbers = param('numbers'); if ( $numbers eq "" ) { &usage; } else { my @nums; #my @lines = split(/\s+/, $numbers) if ($numbers =~ /\s+/); my @lines = split(/\n/, $numbers); #my @lines = split(/,/, @lines) if @lines =~ /,/; foreach my $line (@lines) { if ( $line ne "" ) { chomp $line; split(/\s+/, $line); split(/\n/, $line); split(/,/, $line); push @nums, $line; } } #Sample data #my @num = sort {$a$b} qw( 1 20 21 22 23 24 40 60 100 101 102 140 141 145 ); my @num = sort {$a$b} @nums; my @new = (); my $span = 0; for( my $ii = 0; $ii <= $#num; $ii++ ) { if( defined $num[$ii - 1] && $num[$ii - 1] + 1 == $num[$ii] ) { if( $span == 1 ) { next; } else { $new[$#new] .= '-'; $span = 1; } } elsif( $span == 1 ) { $new[$#new] .= $num[$ii - 1]; push @new, $num[$ii]; $span = 0; } else { push @new, $num[$ii]; } } my @DISPLAY = join(',', @new)."\n"; print "Content-type: text/html\n\n" . "\n\n" . "LAN IP Range Results\n" . "\n" . "\n" . "

LAN IP Range Results

\n" . "

\n" . "\n"; print "@DISPLAY"; print "\n" . "\n\n"; exit 0; }

Advertisement

vlanrangeclear_cgi

Filed under: cgi, Cisco, perl — Tags: , , , — lancevermilion @ 11:29 pm
#!/usr/local/bin/perl -w
#Author: Lance Vermilion
#Description: Create a list of vlans in a range format "1,3-300,302-999"
#                 to be cleared on trunk ports.
################################################

use strict;
use warnings;
use CGI qw(:standard);

sub usage () {
print
  "Content-type: text/html\n\n" .
  "\n\n" .
  "Vlan Range Results\n" .
  "\n" .
  "\n" .
  "

ERROR

\n" . "

\n" . "\n"; print "\nYOU MUST FILL OUT EVERY FIELD\n"; print "\n" . "\n\n"; exit 0; } #### # Question for the user #### my $numbers = param('numbers'); if ( $numbers eq "" ) { &usage; } else { #my($beg, $end) = (shift(@ARGV) =~ /^(-?\d+)-(-?\d+)$/) # or die "Usage:\n$0 \n"; my($beg, $end) = (1, 1000); my @lines = split(/\s+/, $numbers); #my @lines = split(/,/, $numbers); my $def = { map { ($_,1) } @lines }; my @num = (); for my $ii ($beg..$end) { push @num, $ii unless defined $def->{$ii}; } my @new = (); my $span = 0; for( my $ii = 0; $ii <= $#num; $ii++ ) { if( defined $num[$ii - 1] && $num[$ii - 1] + 1 == $num[$ii] ) { if( $span == 1 ) { next; } else { $new[$#new] .= '-'; $span = 1; } } elsif( $span == 1 ) { $new[$#new] .= $num[$ii - 1]; push @new, $num[$ii]; $span = 0; } else { push @new, $num[$ii]; } } if( $span == 1 ) { $new[$#new] .= $num[$#num]; } #print join(',', @new)."\n"; my @DISPLAY = join(',', @new)."\n"; print "Content-type: text/html\n\n" . "\n\n" . "LAN IP Range Results\n" . "\n" . "\n" . "

LAN IP Range Results

\n" . "

\n" . "\n"; print "@DISPLAY"; print "\n" . "\n\n"; exit 0; } __END__

tftp_cgi

Filed under: cgi, perl — Tags: , , — lancevermilion @ 11:24 pm
#!/usr/local/bin/perl
#
# Lists files in the /tftpboot folder
#
######################################

@files = `du -h /tftpboot/*`;

format FORMAT_TFTP =
@<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$size,          $filename,
.

print
  "Content-type: text/html\n\n" .
  "\n" .
  "Files in /tftpboot\n" .
  "\n" .
  "\n" .
  "

Files in /tftpboot

\n" . "

\n" . "\n"; print "

\n";

print "File Size       Filename\n";
foreach $eachline (@files) {
  my @line = split(/\//, $eachline);
  $line[1] =~ s/\/tftpboot\///g;
    $size = $line[0];
    $filename = $line[2];
    $~ = 'FORMAT_TFTP';
    write();
}
  print "

\n";
print "\n" .
"


\n" .
"\n";

ipvpnconfig_cgi

Filed under: cgi, perl — Tags: , — lancevermilion @ 11:19 pm
#!/usr/local/bin/perl
#Written By: Lance Vermilion
#Purpose: Create a IPVPN config for MCI IPVPN
###########################################################################

use CGI qw(:standard);

sub usage () {
print
  "Content-type: text/html\n\n" .
  "\n\n" .
  "IPVPN Config Generator\n" .
  "\n" .
  "\n" .
  "

ERROR

\n" . "

\n" . "\n

"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n
\nYOU MUST FILL OUT EVERY FIELD\n
Size = $size
Iata = $iata
OU = $ou
Rtrnum = $rtrnum
tunnelnum = $tunnelnum
needdlsw = $needdlsw
networkaddress = $networkaddress
MCIenetnetwork = $mcienetnetwork
" . "
\n\n"; exit 0; } #### # Question for the user #### $size = param('size'); $iata = param('iata'); $ou = param('ou'); $rtrnum = param('rtrnum'); $tunnelnum = param('tunnelnum'); $needdlsw = param('needdlsw'); $networkaddress = param('networkaddress'); $MCIenetnetwork = param('mcienetnetwork'); #if ( $size eq "" ) { #&usage; #} elsif ( $iata eq "" ) { #&usage; #} elsif ( $ou eq "" ) { #&usage; #} elsif ( $rtrnum eq "" ) { #&usage; #} elsif ( $tunnelnum eq "" ) { #&usage; #} elsif ( $needdlsw eq "" ) { #&usage; #} elsif ( $networkaddress ne "") { #&usage; #} elsif ( $MCIenetnetwork ne "") { ######################################## #### DO NOT CHANGE BELOW THIS POINT #### ######################################## ##### # MCI ENET IP MASSAGING ##### my (@MCIenet) = split(/\./, $MCIenetnetwork); $MCIenet4thoctet = $MCIenet[3] + 1; $MCIrtrenet4thoctet = $MCIenet[3] + 2; $MCIenetIP = "$MCIenet[0].$MCIenet[1].$MCIenet[2].$MCIenet4thoctet"; $MCIrtrenetIP = "$MCIenet[0].$MCIenet[1].$MCIenet[2].$MCIrtrenet4thoctet"; ##### # LAN ENET IP MASSAGING ##### if ( $size eq '/24' ) { my (@ips) = split(/\./, $networkaddress); $ip3octets = "$ips[0].$ips[1].$ips[2]"; $dnetwork = $ip3octets . ".0"; $ip3octetsGRE = "$ips[0].$ips[1].$ips[2]"; $dsubnet = "255.255.255.192"; $subnet = "255.255.255.0"; } elsif ( $size eq '/23' ) { $dsubnet = "255.255.255.128"; my (@ips) = split(/\./, $networkaddress); $ip3octets = "$ips[0].$ips[1].$ips[2]"; $dnetwork = $ip3octets . ".0"; my $ip3rdoctet = $ips[2] + 1; $ip3octetsGRE = "$ips[0].$ips[1].$ip3rdoctet"; $ip3octetsLO = "$ips[0].$ips[1].$ip3rdoctet"; $subnet = "255.255.254.0"; } elsif ( $size eq '/22' ) { $dsubnet = "255.255.255.0"; my (@ips) = split(/\./, $networkaddress); $ip3octets = "$ips[0].$ips[1].$ips[2]"; $dnetwork = $ip3octets . ".0"; my $ip3rdoctet = $ips[2] + 3; $ip3octetsGRE = "$ips[0].$ips[1].$ip3rdoctet"; $ip3octetsLO = "$ips[0].$ips[1].$ip3rdoctet"; $subnet = "255.255.252.0"; } else { print print "\n\n\n" . print "\n\n\n" . print "\nERROR\n" . print "\n\n" . print "\n\n" . print "\n

ERROR

\n" . print "\n

\n" . print "\n\n"; print "\n

"; print "\n"; print "\n
YOU MUST TYPE: /22 or /23 or /24 NOT $size
\n\n"; exit 0; } print "Content-type: text/html\n\n" . "\n\n" . "IPVPN Config Generator\n" . "\n" . "\n" . "\n" . "\n"; if ( $needdlsw eq "yes" ) { if ( $rtrnum eq "1" ) { print "\n"; } else { print "\n"; } print "\n"; print "\n"; print "\n"; print "\n"; } print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; if ( $needdlsw eq "yes" ) { print "\n"; print "\n"; } print "\n"; if ( $rtrnum eq "2" ) { print "\n"; } print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "

\n

“;
print “\n

IPVPN Config -- $iata-$ou
dlsw local-peer peer-id $ip3octets.2
dlsw local-peer peer-id $ip3octets.3
dlsw remote-peer 0 tcp 199.41.124.253 timeout 180
dlsw remote-peer 0 tcp 199.41.124.254 backup-peer 199.41.124.253 timeout 180 linger 3
dlsw icannotreach sap AA F0 FC
!
interface Tunnel$tunnelnum
&nbspdescription GRE Tunnel over MCI Network to us-phx-co01-ich-rt06
&nbspip address $ip3octetsGRE.242 255.255.255.252
&nbspdelay 200
&nbsptunnel source Ethernet0/0
&nbsptunnel destination 7.224.220.2
\!
router eigrp 75
&nbspnetwork 7.0.0.0
&nbspno auto-summary
&nbspno eigrp log-neighbor-changes
\!
ip route $dnetwork $subnet Null0
ip route 199.41.124.253 255.255.255.255 7.231.105.2
ip route 199.41.124.254 255.255.255.255 7.231.105.2
ip route 7.224.220.2 255.255.255.255 $MCIrtrenetIP
ip route $ip3octetsLO.254 255.255.255.255 $ip3octets.2
\!
router bgp 65196
&nbspno synchronization
&nbspbgp log-neighbor-changes
&nbspnetwork $dnetwork mask $subnet
&nbspneighbor $ip3octetsGRE.241 remote-as 65199
&nbspneighbor $ip3octetsGRE.241 next-hop-self
&nbspno auto-summary

\n
IPVPN Config -- us-phx-co01-ich-rt06
interface Tunnel$tunnelnum
&nbspdescription GRE Tunnel over MCI Network to us-$iata-$ou-ice-rt0$rtrnum
&nbspip address $ip3octetsGRE.241 255.255.255.252
&nbsptunnel source GigabitEthernet0/0
&nbsptunnel destination $MCIenetIP
\!
router bgp 65199
&nbspneighbor $ip3octetsGRE.242 remote-as 65196
&nbspneighbor $ip3octetsGRE.242 next-hop-self
&nbspneighbor $ip3octetsGRE.242 distribute-list Default-Only out

\n\n”;

exit 0;

#} else {
# &usage;
#}

iprange_cgi

Filed under: cgi, perl — Tags: , — lancevermilion @ 11:17 pm
#!/usr/local/bin/perl
#Written By: Lance Vermilion
#Purpose: Provided the site size, iata, and ip network address a network ip
#         range will be created and display subnet, gateway, etc
###########################################################################

#Sample output need for David Taylor
#!!!DATA Network ONLY!!!
#7.226.206.0 255.255.255.128 (SUBNET)
#7.226.206.1 (Gateway)
#7.226.206.1-32 (STATIC)
#7.226.206.33-127 (DHCP)
#
#!!!WIRELESS Network ONLY!!!
#7.226.206.128 255.255.255.128 (SUBNET)
#7.226.206.129 (Gateway)
#7.226.206.129-135 (Reserved for Network EQUIPMENT)
#7.226.206.136-254 (WIRELESS Engineering will assign these)
#
#!!!VOICE Network ONLY!!!
#7.226.207.0 255.255.255.128 (SUBNET)
#7.226.207.1 (Gateway)
#7.226.207.1-5 (Reserved for Network EQUIPMENT)
#7.226.207.6-127 (VOICE Engineering will assign these)
#
#!!!Misc Network ONLY!!!
#7.226.207.128 255.255.255.128 (SUBNET)
#7.226.207.129 (Gateway)
#7.226.207.129-133 (Reserved for Network EQUIPMENT)
#7.226.207.134-191 (Network Engineering will assign these)

use CGI qw(:standard);

sub usage () {
print
  "Content-type: text/html\n\n" .
  "\n\n" .
  "LAN IP Range Results\n" .
  "\n" .
  "\n" .
  "

ERROR

\n" . "

\n" . "\n"; print "\nYOU MUST FILL OUT EVERY FIELD\n"; print "\n" . "\n\n"; exit 0; } #### # Question for the user #### $size = param('size'); $iata = param('iata'); $factype = param('ou'); $networkaddress = param('network'); uc($iata); uc($factype); if ( $size eq "" ) { &usage; } elsif ( $iata eq "" ) { &usage; } elsif ( $factype eq "" ) { &usage; } elsif ( $networkaddress ne "") { ######################################## #### DO NOT CHANGE BELOW THIS POINT #### ######################################## if ( $size eq '/24' ) { #### # SMALL SITES #### my (@ips) = split(/\./, $networkaddress); $ip3octets = "$ips[0].$ips[1].$ips[2]"; ########## # DATA ########## $dsubnet = "255.255.255.192"; $dgw = $ip3octets . ".1"; $dres = $ip3octets . ".1-15"; $ddhcp = $ip3octets . ".16-62"; $dnetwork = $ip3octets . ".0"; ########## # WIRELESS ########## $wsubnet = "255.255.255.192"; $wgw = $ip3octets . ".65"; $wres = $ip3octets . ".65-71"; $wdhcp = $ip3octets . ".72-126"; $wnetwork = $ip3octets . ".64"; ########## # VOICE ########## $vsubnet = "255.255.255.192"; $vgw = $ip3octets . ".129"; $vres = $ip3octets . ".129-135"; $vdhcp = $ip3octets . ".136-190"; $vnetwork = $ip3octets . ".128"; ########## # MISC ########## $msubnet = "255.255.255.224"; $mgw = $ip3octets . ".193"; $mres = $ip3octets . ".193-198"; $mdhcp = $ip3octets . ".199-222"; $mnetwork = $ip3octets . ".192"; } elsif ( $size eq '/23' ) { #### # MEDIUM SITES #### my (@ips) = split(/\./, $networkaddress); my $ip3rdoctetw = "$ips[2]"; my $ip3thoctetv = $ips[2] + 1; ########## # DATA ########## $dsubnet = "255.255.255.128"; $ip3octets = "$ips[0].$ips[1].$ips[2]"; $dgw = $ip3octets . ".1"; $dres = $ip3octets . ".1-32"; $ddhcp = $ip3octets . ".33-126"; $dnetwork = $ip3octets . ".0"; ########## # WIRELESS ########## $wsubnet = "255.255.255.128"; $ip2octets = "$ips[0].$ips[1]."; $wgw = $ip2octets . $ip3rdoctetw . ".129"; $wres = $ip2octets . $ip3rdoctetw . ".129-135"; $wdhcp = $ip2octets . $ip3rdoctetw . ".136-254"; $wnetwork = $ip2octets . $ip3rdoctetw . ".128"; ########## # VOICE ########## $vsubnet = "255.255.255.128"; $ip2octets = "$ips[0].$ips[1]."; $vgw = $ip2octets . $ip3thoctetv . ".1"; $vres = $ip2octets . $ip3thoctetv . ".1-7"; $vdhcp = $ip2octets . $ip3thoctetv . ".8-126"; $vnetwork = $ip2octets . $ip3thoctetv . ".0"; ########## # MISC ########## $msubnet = "255.255.255.192"; $mgw = $ip3octets . ".129"; $mres = $ip3octets . ".129-134"; $mdhcp = $ip3octets . ".135-190"; $mnetwork = $ip3octets . ".128"; } elsif ( $size eq '/22' ) { #### # LARGE SITES #### my (@ips) = split(/\./, $networkaddress); my $ip3rdoctetw = $ips[2] + 1; my $ip3thoctetv = $ips[2] + 2; ########## # DATA ########## $dsubnet = "255.255.255.0"; $ip3octets = "$ips[0].$ips[1].$ips[2]"; $dgw = $ip3octets . ".1"; $dres = $ip3octets . ".1-32"; $ddhcp = $ip3octets . ".33-254"; $dnetwork = $ip3octets . ".0"; ########## # WIRELESS ########## $wsubnet = "255.255.255.0"; $ip2octets = "$ips[0].$ips[1]."; $wgw = $ip2octets . $ip3rdoctetw . ".1"; $wres = $ip2octets . $ip3rdoctetw . ".1-7"; $wdhcp = $ip2octets . $ip3rdoctetw . ".8-254"; $wnetwork = $ip2octets . $ip3rdoctetw . ".0"; ########## # VOICE ########## $ip2octets = "$ips[0].$ips[1]."; $vgw = $ip2octets . $ip3thoctetv . ".1"; $vres = $ip2octets . $ip3thoctetv . ".1-7"; $vdhcp = $ip2octets . $ip3thoctetv . ".8-254"; $vnetwork = $ip2octets . $ip3thoctetv . ".0"; ########## # MISC ########## $msubnet = "255.255.255.128"; $mgw = $ip3octets . ".1"; $mres = $ip3octets . ".1-5"; $mdhcp = $ip3octets . ".6-126"; $mnetwork = $ip3octets . ".0"; } else { print "Content-type: text/html\n\n" . "\n\n" . "ERROR\n" . "\n" . "\n" . "

ERROR

\n" . "

\n" . "\n"; print "YOU MUST TYPE: /22 or /23 or /24 NOT $size"; print "

“;

print “\n” .
“\n\n”;
exit 0;
}

print
“Content-type: text/html\n\n” .
“\n\n” .
“LAN IP Range Results\n” .
“\n” .
“\n” .

LAN IP Range Results

\n” .

\n” .
“\n”;
print “

“;
print “

“;
print “

Remote Site: $iata-$factype

“;
print “

“;
print “

DATA Network
“;
print “

“;
print “

“;
print “

“;
print “

“;
print “

“;
print “

“;
print “

$dnetwork   Network Address
$dsubnet   Subnet Mask
$dgw   Default Gateway
$dres   Reserved for Network Equipment / Static Devices
$ddhcp   DHCP
“;
print “

“;
print “

WIRELESS Network
“;
print “

“;
print “

“;
print “

“;
print “

“;
print “

“;
print “

“;
print “

$wnetwork   Network Address
$wsubnet   Subnet Mask
$wgw   Gateway
$wres   Reserved for Network
$wdhcp   WIRELESS Engineering will assign these
“;
print “

“;
print “

VOICE Network
“;
print “

“;
print “

“;
print “

“;
print “

“;
print “

“;
print “

$vnetwork   Network Address
$vsubnet   Subnet Mask
$vgw   Gateway
$vres   Reserved for Network
$vdhcp   VOICE Engineering will assign these
“;
print “

“;
print “

MISC Network
“;
print “

“;
print “

“;
print “

“;
print “

“;
print “

“;
print “

$mnetwork   Network Address
$msubnet   Subnet Mask
$mgw   Gateway
$mres   Reserved for Network
$mdhcp   NETWORK Engineering will assign these

“;
print “\n” .
“\n\n”;

exit 0;

} else {
&usage;
}

dnsdhcpgen_cgi

Filed under: cgi, dhcp, dns, perl — Tags: , , , — lancevermilion @ 11:15 pm
#!/usr/local/bin/perl
#Written By: Lance Vermilion
#Purpose: Provided the site size,iata,facility type, number of router,
#         number of switches, and the network address at the remote site
#         this script will generate the required format that SOG needs to
#         bulk load entires.
###########################################################################

#Sample output need for SOG
#iata,facilitytype,networkaddress,gateway,subnetnetmask,staticdevicerange(#-#),dhcprange(#-#),statics(host, ip)....

use CGI qw(:standard);

sub usage () {
print
  "Content-type: text/html\n\n" .
  "\n\n" .
  "DNS & DHCP Results\n" .
  "\n" .
  "\n" .
  "

ERROR

\n" . "

\n" . "\n"; print "\nYOU MUST FILL OUT EVERY FIELD\n"; print "\n" . "\n\n"; exit 0; } #### # Question for the user #### $size = param('size'); $iata = param('iata'); $factype = param('ou'); $numrtr = param('routers'); $numsw = param('switches'); $networkaddress = param('network'); if ( $size eq "" ) { &usage; } elsif ( $iata eq "" ) { &usage; } elsif ( $factype eq "" ) { &usage; } elsif ( $numrtr eq "" ) { &usage; } elsif ( $numsw eq "" ) { &usage; } elsif ( $networkaddress ne "") { ######################################## #### DO NOT CHANGE BELOW THIS POINT #### ######################################## if ( $size eq '/24' ) { #### # SMALL SITES #### my (@ips) = split(/\./, $networkaddress); $ip3octets = "$ips[0].$ips[1].$ips[2]"; @staticdevices; @staticdevicesDHL; @staticdevicesTOOLS; ## ##SWITCH ## $ip4thoctet = "4"; for ( $count = 1; $count <= $numsw; $count++ ) { chomp ($val = "us-$iata-$factype-ice-sw0$count,$ips[0].$ips[1].$ips[2].$ip4thoctet"); chomp ($valDHL = "us-$iata-$factype-ice-sw0$count 86400 IN CNAME us-$iata-$factype-ice-sw0$count.us.dhl.com."); chomp ($valTOOLS = "us-$iata-$factype-ice-sw0$count.dhl.com,$ips[0].$ips[1].$ips[2].$ip4thoctet"); push @staticdevices, $val; push @staticdevicesDHL, $valDHL; push @staticdevicesTOOLS, $valTOOLS; $ip4thoctet++; } ## ##ROUTER ## $rtrip4thoctet = "254"; for ( $count = 1; $count <= $numrtr; $count++ ) { chomp ($val = "us-$iata-$factype-ice-rt0$count,$ips[0].$ips[1].$ips[2].$rtrip4thoctet"); chomp ($valDHL = "us-$iata-$factype-ice-rt0$count 86400 IN CNAME us-$iata-$factype-ice-rt0$count.us.dhl.com."); chomp ($valTOOLS = "us-$iata-$factype-ice-rt0$count.dhl.com,$ips[0].$ips[1].$ips[2].$rtrip4thoctet"); push @staticdevices, $val; push @staticdevicesDHL, $valDHL; push @staticdevicesTOOLS, $valTOOLS; $rtrip4thoctet--; } ## ##DO NOT CHANGE VARIABLES BELOW ## $staticdevices = join(",", @staticdevices); $staticdevicesDHL = join("\n", @staticdevicesDHL); $staticdevicesTOOLS = join("\n", @staticdevicesTOOLS); $subnet = "255.255.255.192"; $gw = $ip3octets . ".1"; $network = $ip3octets . ".0"; $staticrange = "1-15"; $dhcprange = "16-62"; } elsif ( $size eq '/23' ) { #### # MEDIUM SITES #### my (@ips) = split(/\./, $networkaddress); $ip3octets = "$ips[0].$ips[1].$ips[2]"; @staticdevices; @staticdevicesDHL; @staticdevicesTOOLS; ## ##SWITCH ## $ip4thoctet = "4"; for ( $count = 1; $count <= $numsw; $count++ ) { chomp ($val = "us-$iata-$factype-ice-sw0$count,$ips[0].$ips[1].$ips[2].$ip4thoctet"); chomp ($valDHL = "us-$iata-$factype-ice-sw0$count 86400 IN CNAME us-$iata-$factype-ice-sw0$count.us.dhl.com."); chomp ($valTOOLS = "us-$iata-$factype-ice-sw0$count.dhl.com,$ips[0].$ips[1].$ips[2].$ip4thoctet"); push @staticdevices, $val; push @staticdevicesDHL, $valDHL; push @staticdevicesTOOLS, $valTOOLS; $ip4thoctet++; } ## ##ROUTER ## $rtrip3rdoctet = $ips[2] += 1; $rtrip4thoctet = "254"; for ( $count = 1; $count <= $numrtr; $count++ ) { chomp ($val = "us-$iata-$factype-ice-rt0$count,$ips[0].$ips[1].$rtrip3rdoctet.$rtrip4thoctet"); chomp ($valDHL = "us-$iata-$factype-ice-rt0$count 86400 IN CNAME us-$iata-$factype-ice-rt0$count.us.dhl.com."); chomp ($valTOOLS = "us-$iata-$factype-ice-rt0$count.dhl.com,$ips[0].$ips[1].$rtrip3rdoctet.$rtrip4thoctet"); push @staticdevices, $val; push @staticdevicesDHL, $valDHL; push @staticdevicesTOOLS, $valTOOLS; $rtrip4thoctet--; } ## ##DO NOT CHANGE VARIABLES BELOW ## $staticdevices = join(",", @staticdevices); $staticdevicesDHL = join("\n", @staticdevicesDHL); $staticdevicesTOOLS = join("\n", @staticdevicesTOOLS); $subnet = "255.255.255.128"; $gw = $ip3octets . ".1"; $network = $ip3octets . ".0"; $staticrange = "1-31"; $dhcprange = "32-126"; } elsif ( $size eq '/22' ) { #### # LARGE SITES #### my (@ips) = split(/\./, $networkaddress); $ip3octets = "$ips[0].$ips[1].$ips[2]"; @staticdevices; @staticdevicesDHL; @staticdevicesTOOLS; ## ##SWITCH ## $ip4thoctet = "4"; for ( $count = 1; $count <= $numsw; $count++ ) { chomp ($val = "us-$iata-$factype-ice-sw0$count,$ips[0].$ips[1].$ips[2].$ip4thoctet"); chomp ($valDHL = "us-$iata-$factype-ice-sw0$count 86400 IN CNAME us-$iata-$factype-ice-sw0$count.us.dhl.com."); chomp ($valTOOLS = "us-$iata-$factype-ice-sw0$count.dhl.com,$ips[0].$ips[1].$ips[2].$ip4thoctet"); push @staticdevices, $val; push @staticdevicesDHL, $valDHL; push @staticdevicesTOOLS, $valTOOLS; $ip4thoctet++; } ## ##ROUTER ## $rtrip3rdoctet = $ips[2] += 3; $rtrip4thoctet = "254"; for ( $count = 1; $count <= $numrtr; $count++ ) { chomp ($val = "us-$iata-$factype-ice-rt0$count,$ips[0].$ips[1].$rtrip3rdoctet.$rtrip4thoctet"); chomp ($valDHL = "us-$iata-$factype-ice-rt0$count 86400 IN CNAME us-$iata-$factype-ice-rt0$count.us.dhl.com."); chomp ($valTOOLS = "us-$iata-$factype-ice-rt0$count.dhl.com,$ips[0].$ips[1].$rtrip3rdoctet.$rtrip4thoctet"); push @staticdevices, $val; push @staticdevicesDHL, $valDHL; push @staticdevicesTOOLS, $valTOOLS; $rtrip4thoctet--; } ## ##DO NOT CHANGE VARIABLES BELOW ## $staticdevices = join(",", @staticdevices); $staticdevicesDHL = join("\n", @staticdevicesDHL); $staticdevicesTOOLS = join("\n", @staticdevicesTOOLS); $subnet = "255.255.255.0"; $gw = $ip3octets . ".1"; $network = $ip3octets . ".0"; $staticrange = "1-31"; $dhcprange = "32-254"; } else { print "Content-type: text/html\n\n" . "\n\n" . "ERROR\n" . "\n" . "\n" . "

ERROR

\n" . "

\n" . "\n"; print "YOU MUST TYPE: /22 or /23 or /24 NOT $size"; print "

“;

print “\n” .
“\n\n”;
exit 0;
}

print
“Content-type: text/html\n\n” .
“\n\n” .
“DNS & DHCP Results\n” .
“\n” .
“\n” .

DNS & DHCP Results

\n” .
Copy the output to the work order that goes to SOG” .

\n” .
“\n”;
print “\n$iata,$factype,$network,$gw,$subnet,$staticrange,$dhcprange,$staticdevices\n\n”;
print “

“;
print “SOG please notify \”AM Secure Access\” when you are done. So they can complete their work order.“;
print “

“;
print “\n\nCopy the output to the work order that goes to Secure Access\n\n“;
print “

“;
print “

";
  print "\n$staticdevicesDHL\n";
  print "

“;
print “\nCopy the output to the work order that goes to Network Management Tool\n\n“;
print “

“;
print “

";
  print "$staticdevicesTOOLS\n";
  print "

“;
print “\n” .
“\n\n”;

exit 0;

} else {
&usage;
}

ciscopricelist_cgi

Filed under: cgi, perl — Tags: , , — lancevermilion @ 11:12 pm
#!/usr/local/bin/perl -w
#Author:  Lance Vermilion
#Purpose: Search the Cisco price list that is tab delimited and then
#         return the values that are found.
##########################################################################

use CGI qw(:standard);

####
# Variables
####

  my $searchval = param('searchval');
  my $file = '/usr/local/www/data/ciscopricelist/global.txt';
  my $count = 0;
  my @data;

####
# Open the that is specified as the variable $file
####
open my $fh, '<', $file
  or die $!;

####
# This is our usage page. It is used when someone doesn't enter data
####
sub usage () {
print
  "Content-type: text/html\n\n" .
  "\n\n" .
  "Cisco Price List Search Results\n" .
  "\n" .
  "\n" .
  "

ERROR

\n" . "

\n" . "\n"; print "\nYOU MUST FILL OUT EVERY FIELD\n"; print "\n" . "\n\n"; exit 0; } #### # Check to see if the user entered something, if not error and exit #### if ( $searchval eq "" ) { &usage; exit 0; } #### # While the file is open search for stuff and push entires into an array #### while() { chomp; if ( /$searchval/i ) { $count++ ; if ( /^[a-zA-Z]/i ) { my @columns = split/ /; #print " # $columns[0] # "; push @data, "$columns[0]"; } elsif ( /^\t[a-zA-Z0-9]/i ) { @columns = split/ /; #print " #  &nbsp$columns[1] # "; push @data, " &nbsp$columns[1]"; } else { @columns = split/ /; #print "   &nbsp$columns[2]$columns[3]$columns[4]$columns[ 5]"; push @data, "   &nbsp$columns[2]$columns[3]$columns[4]$col umns[5]"; } } } close($fh); #### # Print webpage #### print "Content-type: text/html\n\n" . "\n\n" . "Cisco Price List\n" . "\n" . "\n" . "

Results while searching for: $searchval

\n" . "

\n" . "\n"; print "Found $count matches for $searchval in the Cisco Price List\n"; print "

";
  print "";
  if (! @data )
  {
    print "NO MATCH found for $searchval";
  }
  else
  {
    print @data;
  }
  print "
"; print "
"; print 'Comments or Questions email Lance Vermilion'; print "

\n";

####
# Exit the cgi script once it is done
####
exit 0;

Create a free website or blog at WordPress.com.