All pastes #509649 Raw Edit

Someone

public php v1 · immutable
·published 2007-05-25 15:57 UTC
rendered paste body
<?php//preg_match('/([a-zA-Z\-_]+\.)+[a-zA-Z]{2,6}$/', $dns);//preg_match('/^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$/', $inet_addr['ipv4']);//preg_match('/^(([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4})$|^([A-Fa-f0-9]{1,4}::([A-Fa-f0-9]{1,4}:){0,5}[A-Fa-f0-9]{1,4})$|^(([A-Fa-f0-9]{1,4}:){2}:([A-Fa-f0-9]{1,4}:){0,4}[A-Fa-f0-9]{1,4})$|^(([A-Fa-f0-9]{1,4}:){3}:([A-Fa-f0-9]{1,4}:){0,3}[A-Fa-f0-9]{1,4})$|^(([A-Fa-f0-9]{1,4}:){4}:([A-Fa-f0-9]{1,4}:){0,2}[A-Fa-f0-9]{1,4})$|^(([A-Fa-f0-9]{1,4}:){5}:([A-Fa-f0-9]{1,4}:){0,1}[A-Fa-f0-9]{1,4})$|^(([A-Fa-f0-9]{1,4}:){6}:[A-Fa-f0-9]{1,4})$/', $inet_addr['ipv6']);// Full IP : 2001:618:400:d9b8:204:23ff:fe5a:4416// IP in 2 parts with the first part of 2 bytes   2001::23ff:fe5a:4416//                   second                  2001:ede::23ff:fe5a:4416//                   third                   2001:ede:a21::23ff:fe5a//                   fourth                  2001:ede:a21:365::23ff:fe5a//                   fifth                   ...//                   last (sixth)/*function __autoload($class) {  require_once 'class.' . $class . '.php';}*/class ipag {  public $inet_addr; // array('ipv1' => '', 'ipv2' => '', 'ipv3' => '', 'ipv4' => '', 'ipv5' => '', 'ipv6' => '');  public function __construct($inet_addr = '0.0.0.0') {    if (preg_match('/^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$/', $inet_addr)) {      $this->inet_addr = explode('.', $inet_addr);    }  }  public function increment() {    if ($this->inet_addr[3] >= 255) {      $this->inet_addr[3] = '0';      if ($this->inet_addr[2] >= 255) {        $this->inet_addr[2] = '0';        if ($this->inet_addr[1] >= 255) {          $this->inet_addr[1] = '0';          if ($this->inet_addr[0] >= 255) {            $this->__construct(); // This can be set to either construct/destruct, depending how you want it to end...          }        }        else {          $this->inet_addr[1]++;        }      }      else {        $this->inet_addr[2]++;      }    }    else {      $this->inet_addr[3]++;    }  }  public function __destruct() {    unset($this->inet_addr);  }}class ipap {  public $socket;  public $host;  public $port;  public $errno;  public $errstr;  public $timeout;  public function __construct($host = '127.0.0.1', $port = '0', $timeout = '1') {    if (preg_match('/^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$/', $host)) {      $this->host = $host;    }    else {      $this->host = '127.0.0.1';    }    if (preg_match('/^([0-9]{1,4})$|^([0-6]{1,1}[0-5]{1,1}[0-5]{1,1}[0-3]{1,1}[0-5]{1,1})$/', $port)) {      $this->port = $port;    }    else {      $this->port = '0';    }    if (preg_match('/^([0-9]{1,3})$/', $timeout)) {      $this->timeout = $timeout;    }    else {      $this->timeout = '1';    }  }  public function increment() {    if ($this->port >= '65536') {      $this->__construct(); // This can be set to either construct/destruct, depending how you want it to end...    }    else {      $this->socket = @fsockopen($this->host, $this->port, $this->errno, $this->errstr, $this->timeout);      if ($this->socket) {        return array($this->host, $this->port);        fclose($this->socket);      }      $this->port++;    }  }  public function __destruct() {    unset($this->socket, $this->host, $this->port, $this->errno, $this->errstr, $this->timeout);  }}$ipag = new ipag;$ipag->__construct('198.166.228.195');$log = fopen('hosts.log', "w");$loop = true;while ($loop) {  $inet_addr = array();  $inet_addr['ipv4'] = implode('.', $ipag->inet_addr);  $inet_addr['ipv4_padded'] = NULL;  foreach ($ipag->inet_addr as $key => $octal) {    if ($key !== end(array_keys($ipag->inet_addr))) {      $inet_addr['ipv4_padded'] .= str_pad($octal, '3', '0', STR_PAD_LEFT) . '.';    }    else {      $inet_addr['ipv4_padded'] .= str_pad($octal, '3', '0', STR_PAD_LEFT);    }  }  $ipag->increment();  if ($inet_addr['ipv4'] === '255.255.255.255') {    $loop = false;  }  else {    $loop = true;  }  if ($inet_addr['ipv4'] !== gethostbyaddr($inet_addr['ipv4'])) {    // fwrite($log, 'inet_addr: ' . $inet_addr . "\t" . 'Host Resolved: ' . gethostbyaddr($inet_addr) . "\n");    print 'inet_addr: ' . $inet_addr['ipv4_padded'] . "\t" . 'Host Resolved: ' . gethostbyaddr($inet_addr['ipv4']) . "\n";    //$ipap = new ipap($inet_addr['ipv4'], '0');    $ipap->__construct('255.0.0.0', '65535');    while ($loop) {      if ($ipap->increment() === true) {        print "\t" . $ipap->port . ' is open.' . "\n";      }      else {        print "\t" . $ipap->port . ' is closed.' . "\n";      }      if ($ipap->port === '65535') {        $loop = false;      }      else {        $loop = true;      }    }  }  else {    print 'inet_addr: ' . $inet_addr['ipv4_padded'] . ' is offline.' . "\n";  }}?>