Skip to content

Instantly share code, notes, and snippets.

@mizzy
Created October 3, 2012 04:22
Show Gist options
  • Select an option

  • Save mizzy/3824987 to your computer and use it in GitHub Desktop.

Select an option

Save mizzy/3824987 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
my @networks = qw( 192.168.47 192.168.48 );
my $ifconfig = `ifconfig eth1|grep 192.168`;
my ( $ipaddr ) = ( $ifconfig =~ /inet addr:([0-9\.]+)/ );
my $gw = $ipaddr;
$gw =~ s/([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+/$1.1/g;
for my $network ( @networks ) {
if ( $ipaddr !~ /$network/ ) {
`route add -net ${network}.0 netmask 255.255.255.0 gw $gw`;
}
}
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment