Commit e5176a90 authored by Mac Newbold's avatar Mac Newbold

Added two-way translation.

parent 65a8a347
#!/usr/local/bin/perl -w
if ($#ARGV < 0) {die("Usage: mac2if <mac> <mac> <...>\n");}
if ($#ARGV < 0) {die("Usage: mac2if <mac|if> <mac|if> <...>\n");}
use Mysql;
......@@ -9,10 +9,19 @@ my $dbh = Mysql->connect("localhost","tbdb","script","none");
my @list = "";
my $n=0;
foreach my $mac ( @ARGV ) {
$mac =~ s/^(\d):/0$1:/;
$mac =~ s/:(\d):/:0$1:/g;
$mac =~ s/://g;
$list[$n] ="MAC='\L$mac'";
if ( $mac =~ /^tb(\w+\d+):(\d+)$/ ) {
my $node="tb".$1;
my $if=$2;
$list[$n] .= "(node_id='$node' and card='$if')";
} elsif ( $mac =~ /^tb(\w+\d+)$/ ) {
my $node="tb".$1;
$list[$n] .= "(node_id='$node')";
} else {
$mac =~ s/^(\d):/0$1:/;
$mac =~ s/:(\d):/:0$1:/g;
$mac =~ s/://g;
$list[$n] ="MAC='\L$mac'";
}
$n++;
}
......
......@@ -9,13 +9,22 @@ my $dbh = Mysql->connect("localhost","tbdb","script","none");
my @list = "";
my $n=0;
foreach my $node ( @ARGV ) {
$list[$n] ="node_id='$node'";
if ( $node =~ /^tb(\w+\d+):(\d+)$/ ) {
my $node_id="tb".$1;
my $if=$2;
$list[$n] .= "(node_id='$node_id' and card='$if')";
} elsif ( $node =~ /^tb(\w+\d+)$/ ) {
my $node_id="tb".$1;
$list[$n] .= "(node_id='$node_id')";
} else {
$list[$n] ="node_id='$node' or IP='$node'";
}
$n++;
}
my $cond = join(" or ",@list);
my $sth = $dbh->
query("select * from IP_list where $cond");
query("select * from interfaces where $cond");
print $sth->as_string();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment