Underc0de

Programación Web => Back-end => Mensaje iniciado por: ANTRAX en Febrero 24, 2010, 11:33:18 AM

Título: [PHP] Soket0n xD
Publicado por: ANTRAX en Febrero 24, 2010, 11:33:18 AM
script medio

Código (php) [Seleccionar]

<?php

// c0ded by v3n0m - 16/02/2009 - 05:54 Am
// Name : Soket0n xD

function connection($remote$port$timeout 45) {
$ip "";
if( !preg_match('/^\d+\.\d+\.\d+$/'$remote) ){
$ip gethostbyname($remote);
if ($ip == $remote) {
$this->errstr "error connection socket: Unknown host";
return NULL;
}
} else $ip $remote;

if (!($this->_SOCK = @socket_create(AF_INETSOCK_STREAMSOL_TCP))) {
$this->errstr "Error creatin Socket: ".socket_strerror(socket_last_error());
return NULL;
}

socket_set_nonblock($this->_SOCK);

$error NULL;
$attempts 0;
$timeout 1000;
$connected;

while(!($connected = @socket_connect($this->_SOCK$remote$posrt+0)) && $attempts++ < $timeout) {
$error socket_last_error();
if($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) {
$this->errstr "Error connecting socket: ".socket_strerror($error);
socket_close($this->_SOCK);
return NULL;
}
usleep(1000);
}

if(!$connected) {
$this->errstr "Error connecting socket: Connect timed out after $timeout seconds"socket_strerror(socket_last_error());
socket_close($this->_SOCK);
return NULL;
}

socket_set_blok($this->_SOCK);

return 1;

}
?>