forked from vanhauser-thc/thc-ipv6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grep6.pl
executable file
·43 lines (37 loc) · 912 Bytes
/
grep6.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl
# basic code by Eric Vyncke
use Socket;
use Socket6;
$fd = STDIN;
$option = shift;
$count = 0;
$ln = 0;
if ($option eq "" || $option eq "-h") {
print "Syntax: grep6.pl [-n] ipv6-address [logfile]\n";
print "Option: -n print with line count\n";
exit(0);
}
if ($option eq "-n") {
$count = 1;
$option = shift;
}
my (@words, $word, $binary_address, $address) ;
$address = inet_pton AF_INET6, $option ;
if (! $address) { die "Wrong IPv6 address passed as argument" ; }
$option2 = shift;
if ($option2 ne "") {
open $fd, "< $option2" or die "$option2";
}
## go through the file one line at a time
while (my $line = <$fd>) {
$ln++;
@words = split /[ ,"'.\\\t\n\r\(\)\[\]]/, $line ;
foreach $word (@words) {
$binary_address = inet_pton AF_INET6, $word ;
if ($binary_address eq $address) {
print "$ln: " if ($count == 1);
print $line ;
next ;
}
}
}