Skip to content

Instantly share code, notes, and snippets.

@roktas
Created April 12, 2010 22:44
Show Gist options
  • Save roktas/364089 to your computer and use it in GitHub Desktop.
Save roktas/364089 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# STDIN'den mac adreslerini topla ve dhcp stanza üret
# örnek kullanım: ./macator </var/log/syslog >out
use strict;
use warnings;
my $d = "[0-9A-Fa-f]";
my $dd = "$d$d";
my %mac = (
# örnek bir kayıt
'00:1e:0b:7b:d2:fd' => 1,
# kalanları da böyle manuel eklersen istediğin sayıda basar
);
while (<>) {
if (/($dd([:-])$dd(\2$dd){4})/o && !$mac{$1}) {
$mac{$1}++;
}
}
my $i = 0;
foreach my $m (sort keys %mac) {
my $ip = $i + 2;
print "host nokta${i} {\n\thardware ethernet $m;\n\tfixed-address 192.168.1.$ip;\n}\n";
$i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment