Version: 1.0.0
Type: Class
Category: Networking
License: GNU General Public License
Description: libident.php is an RFC 1413 compatible PHP4 Ident client class. The Identification Protocol (a.k.a., “ident”, a.k.a., “the Ident Protocol”) provides a means to determine the identity of a user of a particular TCP connection. Given a TCP port number pair, it returns a character string which identifies the owner of that connection on the server’s system.
<?php /* Find out more about the Ident protocol at http://www.ietf.org/rfc/rfc1413.txt */ class ident { var $data; var $int_errormsg; var $status = 1; function ident($peeraddr, $peerport, $localport) { $identport = 113; $timeout = 30; $socket = @fsockopen($peeraddr, $identport, $errno, $errstr, $timeout); if (!$socket) { $this->int_errormsg = "Error connecting to ident server ($peeraddr:$identport): $errstr ($errno)"; $this->status = 0; return false; } @fputs($socket, "$peerport, $localportrn"); $line = @fgets($socket, 512); $this->data['rawdata'] = $line; list($undef, $response) = explode(":", $line, 2); list($resp_type, $add_info) = explode(":", trim($response), 2); fclose($socket); if (trim($resp_type) == 'ERROR') { $this->int_errormsg = trim($add_info); $this->status = 0; return false; } elseif (trim($resp_type) == 'USERID') { list($os_type, $username) = explode(":", trim($add_info), 2); $this->data['username'] = trim($username); $this->data['os_type'] = trim($os_type); return true; } else { $this->int_errormsg = 'Unknown error'; $this->status = 0; return false; } } function user() { if ($this->data['username']) { return $this->data['username']; } else { $this->int_errormsg = 'Server returned an error, or no query has been made yet.'; return false; } } function os_type() { if ($this->data['os_type']) { return $this->data['os_type']; } else { $this->int_errormsg = 'Server returned an error, or no query has been made yet.'; return false; } } function error() { return $this->int_errormsg; } function data($key) { return $this->data[$key]; } } ?>