#!/usr/bin/perl use IPC::Open2; $nc="/usr/local/bin/nc"; $total=""; while () { $orig_line=$_; if ( $orig_line =~ /(http:\/\/linuxfr.org\/redirect\/[0-9]+\.html)/ ) { $url=$1; $newurl = &detect_redir($url); $orig_line =~ s/$url/$newurl/; } # print $orig_line; $total .= $orig_line; } print "$total"; sub detect_redir { local $retour=""; local $urlorig=shift; $siteurl = $urlorig; $siteurl =~ s/http:\/\/linuxfr.org//; $pid = open2(*Reader, *Writer, $nc, 'www.linuxfr.org', '80' ); print Writer "GET $siteurl HTTP/1.0\n\n"; while () { chop; chop; if ( /Location: (.*)/ ) { $retour = $1; } } close(Writer); close(Reader); waitpid $pid, 0; if ( $retour eq "" ) { $retour=$urlorig; } return $retour; }