'', '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"; } } ?>