#!/usr/bin/perl -w # banip 5/30/2003 by David Efflandt efflandt@xnet.com # Enters a full or partial IP into a file list. # List is sorted and duplicates removed. # # set $file to point to your IP ban list file my $file = "$ENV{HOME}/banlist.txt"; my $newip = shift || 0; my ($iplist,%hash); if ($newip) { $newip .= '.' unless (/\.$/ || /\d+\.\d+\.\d+\.\d+/); $hash{$newip} = pack('C4',split(/\./,$newip)); print "using: $file\n"; } else { warn "usage: $0 ip_addr\n$file is just being sorted\n"; } if (open (IN,"$file")) { while () { chomp; $_ .= '.' unless (/\.$/ || /\d+\.\d+\.\d+\.\d+/); $hash{$_} = pack('C4',split(/\./,$_)); } close IN; } elsif (!$newip) { die "nothing to do!\n"; } else { die "can't read $file: $!\n"; } @iplist = sort { $hash{$a} cmp $hash{$b} } keys %hash; open (OUT,"> $file") || die "Can't write $file: $!"; foreach (@iplist) { print OUT "$_\n"; } close OUT;