puniq: man page

This commit is contained in:
Ole Tange 2017-01-07 21:33:04 +01:00
parent 90946afc5b
commit c4ebb7aae2
4 changed files with 241 additions and 3 deletions

View file

@ -1,12 +1,12 @@
CMD = blink bsearch histogram upsidedown tracefile timestamp rand rrm goodpasswd gitnext ramusage ramusage CMD = blink bsearch histogram upsidedown tracefile timestamp rand rrm goodpasswd gitnext puniq ramusage ramusage
all: blink/blink.1 bsearch/bsearch.1 goodpasswd/goodpasswd.1 histogram/histogram.1 rand/rand.1 rrm/rrm.1 timestamp/timestamp.1 tracefile/tracefile.1 upsidedown/upsidedown.1 wssh/wssh.1 all: blink/blink.1 bsearch/bsearch.1 goodpasswd/goodpasswd.1 histogram/histogram.1 puniq/puniq.1 rand/rand.1 rrm/rrm.1 timestamp/timestamp.1 tracefile/tracefile.1 upsidedown/upsidedown.1 wssh/wssh.1
%.1: % %.1: %
pod2man $< > $@ pod2man $< > $@
install: install:
mkdir -p /usr/local/bin mkdir -p /usr/local/bin
parallel eval ln -sf `pwd`/*/{} /usr/local/bin/{} ::: $(CMD) parallel -v eval ln -sf `pwd`/*/{} /usr/local/bin/{} ::: $(CMD)
mkdir -p /usr/local/share/man/man1 mkdir -p /usr/local/share/man/man1
parallel ln -sf `pwd`/{} /usr/local/share/man/man1/{/} ::: */*.1 parallel ln -sf `pwd`/{} /usr/local/share/man/man1/{/} ::: */*.1

71
blockip/blockip Executable file
View file

@ -0,0 +1,71 @@
#!/usr/bin/perl
# blockip i.p.n.r/bits days
# Block IP-net for some days by routing it to 127.x.y.z
my $ipnet = shift;
my $days = shift;
my ($yy,$mm,$dd) = (localtime(time+24*60*60*$days))[5,4,3];
$yy %=100; # 2 digit year
$mm++; # Perl month from 0..11
my ($octets,$bits) = split m:/:, $ipnet;
$bits ||= 31;
my @ipoctets = split /\./,$octets;
my $ip32 = ip_quad_to_ip32(@ipoctets);
my $net32 = $ip32 & ~(2**(32-$bits) - 1);
my @net = ip32_to_ip_quad($net32);
my @ipnet = join(".",@net);
block($yy,$mm,$dd,$bits,@ipnet);
($yy,$mm,$dd) = (localtime(time))[5,4,3];
$yy %=100; # 2 digit year
$mm++; # Perl month from 0..11
unblock($yy,$mm,$dd);
sub unblock {
my ($yy,$mm,$dd) = @_;
my @routes = `route -n`;
for (@routes) {
my ($net,$gw,$mask,$rest) = split/ +/;
if($gw =~ /^127\.(\d+)\.(\d+)\.(\d+)/) {
# A blackholed route
if("$yy-$mm-$dd" ge "$1-$2-$3") {
# Remove blackhole
print("route del -net $net netmask $mask gw $gw\n");
system("route del -net $net netmask $mask gw $gw");
}
}
}
}
sub block {
my ($yy,$mm,$dd,$bits,@ipnet) = @_;
print("route add -net @ipnet/$bits gw 127.$yy.$mm.$dd\n");
system("route add -net @ipnet/$bits gw 127.$yy.$mm.$dd");
}
sub ip_quad_to_ip32 {
my @ipoctests = @_;
return(
($ipoctets[0] << 24) +
($ipoctets[1] << 16) +
($ipoctets[2] << 8) +
($ipoctets[3] << 0));
}
sub ip32_to_ip_quad {
my $ip32 = shift;
return (
($ip32 >> 24) & 255,
($ip32 >> 16) & 255,
($ip32 >> 8) & 255,
($ip32 >> 0) & 255
);
}

12
blockip/greppct Executable file
View file

@ -0,0 +1,12 @@
#!/usr/bin/perl
# www.pi.dk 107.150.59.98 - - [29/Nov/2016:11:29:01 +0100] "GET /test/?16EE2%20%20%E5%AF%8C%E5%B1%B1%E3%83%8B%E3%83%A5%3%83%BC%E3%83%90%E3%83%A9%E3%83%B3%E3%82%B9996%E8%B2%A9%E5%A3%B2%E5%BA%97%20%20%E3%83%8B%E3%83%A5%E3%83%BC%E3%83%90%E3%83%A9%E3%83%B3%E3%82%B9576%E6%BF%80%E5%AE%89
my $antalpcttegn = shift;
while(<>) {
my @ip = split / /,$_;
my @v = split /"/,$_;
my $c = $v[1]=~y/%/%/;
$c > $antalpcttegn and print $ip[1],"\n";
}

155
puniq/puniq Executable file
View file

@ -0,0 +1,155 @@
#!/usr/bin/perl
=head1 NAME
puniq - print first unique line
=head1 SYNOPSIS
B<puniq> file
cat file | B<puniq>
=head1 DESCRIPTION
B<puniq> works similar to B<uniq>. It prints the line the first time
it is seen.
=head1 EXAMPLES
=head2 dmesg continously
forever dmesg | puniq
=head1 REPORTING BUGS
B<puniq> is part of tangetools. Report bugs to <tools@tange.dk>.
=head1 AUTHOR
Copyright (C) 2017 Ole Tange http://ole.tange.dk
=head1 LICENSE
Copyright (C) 2013 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=head2 Documentation license I
Permission is granted to copy, distribute and/or modify this documentation
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the file fdl.txt.
=head2 Documentation license II
You are free:
=over 9
=item B<to Share>
to copy, distribute and transmit the work
=item B<to Remix>
to adapt the work
=back
Under the following conditions:
=over 9
=item B<Attribution>
You must attribute the work in the manner specified by the author or
licensor (but not in any way that suggests that they endorse you or
your use of the work).
=item B<Share Alike>
If you alter, transform, or build upon this work, you may distribute
the resulting work only under the same, similar or a compatible
license.
=back
With the understanding that:
=over 9
=item B<Waiver>
Any of the above conditions can be waived if you get permission from
the copyright holder.
=item B<Public Domain>
Where the work or any of its elements is in the public domain under
applicable law, that status is in no way affected by the license.
=item B<Other Rights>
In no way are any of the following rights affected by the license:
=over 9
=item *
Your fair dealing or fair use rights, or other applicable
copyright exceptions and limitations;
=item *
The author's moral rights;
=item *
Rights other persons may have either in the work itself or in
how the work is used, such as publicity or privacy rights.
=back
=item B<Notice>
For any reuse or distribution, you must make clear to others the
license terms of this work.
=back
A copy of the full license is included in the file as cc-by-sa.txt.
=head1 DEPENDENCIES
B<puniq> uses Perl.
=head1 SEE ALSO
B<uniq>(1).
=cut
use Digest::MD5 qw(md5);
while(<>) {
$seen{md5($_)}++ or print;
}