Este es mi codigo
Código PHP:
<?php
$agent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/Linux/',$agent)) $os = 'Linux';
elseif(preg_match('/Win/',$agent)) $os = 'Windows';
elseif(preg_match('/Mac/',$agent)) $os = 'Mac';
else $os = 'Desconocido';
if($os!='Desconocido')
{
$delay = 1;
$x = 3;
$port = 23;
$timeout = 180;
$router_ip = '192.168.11.5';
echo "Se establecio el punto terminal en el router!<br><br>";
$y = $_SERVER["REMOTE_ADDR"];
$w = $x + 10;
echo "Su sistema operativo es: $os<br><br>";
switch($os)
{
//windows vista / 2008 / 7
case "Windows":
echo "Copie y pegue estos comandos en su terminal en modo de administrador para completar la conexion:<br>";
echo "netsh interface teredo set state disabled<br>";
echo "netsh interface ipv6 add v6v4tunnel Tunnel".$x." ".$y." ".$router_ip."<br>";
echo "netsh interface ipv6 add address Tunnel".$x." 2001:470:db80:".$x."::".$w."/64<br>";
echo "netsh interface ipv6 add route ::/0 Tunnel".$x." 2001:470:db80:".$x."::".$x."<br>";
echo "<br>O si lo desea, puede descargar este archivo para realizar la configuracion de manera automatica.<br>
Recuerde ejecutarlo en modo de administrador para obtener los permisos necesarios.<br>";
$FileName = "TunnelConfig.bat";
$FileHandle = fopen($FileName, 'w') or die("can't open file");
$string = "netsh interface teredo set state disabled\n";
fwrite($FileHandle, $string);
$string = "netsh interface ipv6 add v6v4tunnel Tunnel".$x." ".$y." ".$router_ip."\n";
fwrite($FileHandle, $string);
$string = "netsh interface ipv6 add address Tunnel".$x." 2001:470:db80:".$x."::".$w."/64\n";
fwrite($FileHandle, $string);
$string = "netsh interface ipv6 add route ::/0 Tunnel".$x." 2001:470:db80:".$x."::".$x."\n";
fwrite($FileHandle, $string);
$string = "PAUSE";
fwrite($FileHandle, $string);
fclose($FileHandle);
break;
//mac os x
case "Mac":
echo "Copie y pegue estos comandos en su terminal para completar la conexion:<br>";
echo "ifconfig Tunnel".$x." create<br>";
echo "ifconfig Tunnel".$x." tunnel ".$y." ".$router_ip."<br>";
echo "ifconfig Tunnel".$x." inet6 2001:470:db80:".$x."::".$w." 2001:470:db80:".$x."::".$x." prefixlen 64<br>";
echo "route -n add -inet6 default 2001:470:db80:".$x."::".$x."<br>";
echo "<br>O si lo desea, puede descargar este archivo para realizar la configuracion de manera automatica.<br>
Recuerde ejecutarlo en modo de administrador pra obtener los permisos necesarios.<br>";
$FileName = "TunnelConfig.sh";
$FileHandle = fopen($FileName, 'w') or die("can't open file");
$string = "ifconfig Tunnel".$x." create\n";
fwrite($FileHandle, $string);
$string = "ifconfig Tunnel".$x." tunnel ".$y." ".$router_ip."\n";
fwrite($FileHandle, $string);
$string = "ifconfig Tunnel".$x." inet6 2001:470:db80:".$x."::".$w." 2001:470:db80:".$x."::".$x." prefixlen 64\n";
fwrite($FileHandle, $string);
$string = "route -n add -inet6 default 2001:470:db80:".$x."::".$x."\n";
fwrite($FileHandle, $string);
fclose($FileHandle);
$osnum = 2;
break;
//debian / ubuntu
case "Linux":
echo "Copie y pegue estos comandos en su terminal para completar la conexion:<br>";
echo "auto Tunnel".$x."<br>";
echo "iface Tunnel".$x." inet6 v4tunnel<br>";
echo "address 2001:470:db80:".$x."::".$w."<br>";
echo "netmask 64<br>";
echo "endpoint ".$router_ip."<br>";
echo "local ".$y."<br>";
echo "ttl 255<br>";
echo "gateway 2001:470:db80:".$x."::".$x."<br>";
echo "<br>O si lo desea, puede descargar este archivo para realizar la configuracion de manera automatica.<br>
Recuerde ejecutarlo en modo de administrador pra obtener los permisos necesarios.<br>";
$FileName = "TunnelConfig.sh";
$FileHandle = fopen($FileName, 'w') or die("can't open file");
$string = "auto Tunnel".$x."\n";
fwrite($FileHandle, $string);
$string = "iface Tunnel".$x." inet6 v4tunnel\n";
fwrite($FileHandle, $string);
$string = "address 2001:470:db80:".$x."::".$w."\n";
fwrite($FileHandle, $string);
$string = "netmask 64\n";
fwrite($FileHandle, $string);
$string = "endpoint ".$router_ip."\n";
fwrite($FileHandle, $string);
$string = "local ".$y."\n";
fwrite($FileHandle, $string);
$string = "ttl 255\n";
fwrite($FileHandle, $string);
$string = "gateway 2001:470:db80:".$x."::".$x."\n";
fwrite($FileHandle, $string);
fclose($FileHandle);
break;
}
// grab the requested file's name
$file_name = $FileName;
// make sure it's a file before doing anything!
if(is_file($file_name))
{
// required for IE
if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); }
// get the file mime type using the file extension
switch(strtolower(substr(strrchr($file_name, '.'), 1))) {
case 'bat': $mime = 'application/octet-stream'; break;
case 'sh': $mime = 'application/x-sh'; break;
default: $mime = 'application/force-download';
}
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($file_name)).' GMT');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file_name)); // provide file size
header('Connection: close');
readfile($file_name); // push it out
exit();
}
}
else
{
echo "No se pudo detectar su sistema operativo.";
}
?>