#!/bin/ksh
#
# Usage: cat FILES | blinks
#
# Where: FILES is a list of files to be scaned for Hyper-Links.
#
# The blinks will hping each link and if a response is returned
# glean from the
.* a synopsis building blinks.html
# file.
#
print '
Links by blinks
' >blinks.html
perl -e '
while () {
if (m,http://[-~/.A-Za-z0-9]+,) {
print "$&\n";
}
}
' | sort -u | perl -e '
$* = 1;
while (<>) {
chomp();
$url = $_;
Again:;
$status = "";
$html = "";
$http = "";
print STDERR "---- $url == ";
$url =~ m,http://([^/]+),;
$text = `./hping -T 5 -i 0 -v -h '\''Host: $1'\'' '\''$url'\''`;
while ($text ne "") {
$text =~ /^.*$/;
$line = $&;
$text = substr($'\'', 1);
$line =~ s/\r//;
if ($status eq "") {
$line =~ /^HTTP\/\d+\.\d+ (\d+.*)$/;
if (($status = $1) ne "") {
if ($status =~ /^200/) {
$html = "title";
} elsif ($status =~ /^302/) {
$http = "Location";
} else {
last;
}
}
} elsif ($html ne "" &&
($$html ne "" || $line =~ /<$html>/i)) {
$line = $'\'' if ($$html eq "");
if ($line =~ m,$html>,i) {
$$html .= " $`";
last;
} else {
$$html .= " $line";
}
} elsif ($http ne "" && $line =~ /$http: (.*)/) {
$$http = $1;
last;
} else {
;
}
}
print STDERR "$status: ";
if ($status =~ /^200/) {
$$html = $url if ($$html =~ /^\s*$/);
print "- $$html\r\n";
print STDERR "$$html\n";
$$html = "";
} elsif ($status =~ /^302/) {
if ($$http =~ m,^/,) {
$url =~ m,^(http://[^/]+),;
$url = $1.$$http;
} else {
$url = $$http;
}
print STDERR "Redirect to $$http\n";
$$http = "";
goto Again;
} else {
print STDERR "???\n";
}
}' >>blinks.html
print '
' >>blinks.html