function search_whois($query) { if (eregi(".com\$", $query) || eregi(".net\$", $query) || eregi(".org\$", $query)) { $server = $GLOBALS[whois_server1]; } else { $server = $GLOBALS[whois_server2]; } $fp = fsockopen($server, 43, &$errno, &$errstr); if (!$fp) { print_message("WHOIS 서버에 접속할수가 없습니다. 잠시후 다시 시도하세요"); return; } set_socket_blocking($fp, 1); fputs($fp, "{$query}\n"); while ($buf = fgets($fp, 255)) { $result .= $buf; } fclose($fp); echo "\n<table cellspacing=0 width=600>\n<tr bgcolor=#eaeaea><td height=30><font size=3><b> 검색결과 - \n <a href=\"http://{$query}\" target=_new>{$query}</a></b></font></td></tr>\n<tr><td><br>\n\t<pre>{$result}</pre>\n </td>\n</tr>\n</table> \t\n"; }
function connect($server, $port = 110) { // Opens a socket to the specified server. Unless overridden, // port defaults to 110. Returns true on success, false on fail // If MAILSERVER is set, override $server with it's value if (!empty($this->MAILSERVER)) { $server = $this->MAILSERVER; } if (empty($server)) { $this->ERROR = "POP3 connect: No server specified"; unset($this->FP); return false; } $fp = fsockopen("{$server}", $port, &$errno, &$errstr); if (!$fp) { $this->ERROR = "POP3 connect: Error [{$errno}] [{$errstr}]"; unset($this->FP); return false; } set_socket_blocking($fp, -1); $this->update_timer(); $reply = fgets($fp, $this->BUFFER); $reply = $this->strip_clf($reply); if ($this->DEBUG) { error_log("POP3 SEND [connect: {$server}] GOT [{$reply}]", 0); } if (!$this->is_ok($reply)) { $this->ERROR = "POP3 connect: Error [{$reply}]"; unset($this->FP); return false; } $this->FP = $fp; $this->BANNER = $this->parse_banner($reply); $this->RFC1939 = $this->noop(); if ($this->RFC1939) { $this->ERROR = "POP3: premature NOOP OK, NOT an RFC 1939 Compliant server"; $this->quit(); return false; } return true; }
function retrieveXML() { $rval = 1; $sp = @fsockopen($this->host, $this->port, $errno, $errstr, 10); if (!$sp) { $rval = 0; } else { set_socket_blocking($sp, false); // request xml data from sc server fputs($sp, "GET /admin.cgi?pass={$this->password}&mode=viewxml HTTP/1.1\nUser-Agent:Mozilla\n\n"); // if request takes > 15s then exit for ($i = 0; $i < 30; $i++) { if (feof($sp)) { break; } // exit if connection broken $sp_data .= fread($sp, 31337); usleep(500000); } // strip useless data so all we have is raw sc server XML data $sp_data = ereg_replace("^.*<!DOCTYPE", "<!DOCTYPE", $sp_data); // plain xml parser $this->parser = xml_parser_create(); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "startElement", "endElement"); xml_set_character_data_handler($this->parser, "characterData"); if (!xml_parse($this->parser, $sp_data, 1)) { $rval = -1; } xml_parser_free($this->parser); } return $rval; }
function get_url($array) { /* defaults (there is no default for 'url' or 'content') */ $robot_rules = TRUE; /* follow the robots.txt standard */ $req_mthd = 'GET'; $protocol = 'HTTP/1.0'; $user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.8.1.7) Gecko/20070914 (FoxPlus) Firefox/2.0.0.7'; $time_out = 10; /* for each argument set in the array, overwrite default */ while (list($k, $v) = each($array)) { ${$k} = $v; } /* set up the cookies. If it exists, the straight variable will be written above ($$k=$v). */ if (is_array($cookies)) { $cookies2send = ''; while (list($k, $v) = each($cookies)) { $cookies2send .= "Cookie: {$k}=" . urlencode($v) . "\n"; } } if (!isset($url)) { return array("content" => ' ', "headers" => ' ', "errcode" => -1, "errmsg" => 'Fatal Error: No URL defined'); } $parsed_url = parse_url("{$url}"); if ($robot_rules) { $robots_url = $parsed_url["scheme"] . "://" . $parsed_url["host"]; if ($parsed_url["port"]) { $robots_url .= ":" . $parsed_url["port"]; } $robots_url .= "/robots.txt"; if (!$this->robot_rules($url, $robots_url, $user_agent)) { return array("content" => ' ', "headers" => ' ', "errcode" => 0, "errmsg" => "Non-fatal Error: Robot Rules do not permit this browser to access {$url}"); } } $req_mthd = strtoupper($req_mthd); // 2068 rfc says it's case sensitive. $host = $parsed_url["host"]; if (!$host || $host == '' || !isset($host)) { array("content" => ' ', "headers" => ' ', "errcode" => -1, "errmsg" => 'Fatal Error: No URL defined'); } $path = $parsed_url["path"]; if (!$path || $path == '' || !isset($path)) { $path = "/"; } $query = $parsed_url["query"]; if ($query != '') { $path = "{$path}?{$query}"; } if (!isset($parsed_url["port"])) { $port = 80; } else { $port = $parsed_url["port"]; } $timeout = time() + $time_out; $fp = fsockopen("{$host}", $port, $errno, $errstring, $time_out); if (!$fp) { return array("content" => ' ', "headers" => ' ', "errcode" => 0, "errmsg" => "Non-Fatal Error: Could not make connection to url {$url} (not found in DNS or you are not connected to the Internet)"); } else { set_socket_blocking($fp, 0); // seems to work either way $REQUEST = "{$req_mthd} {$path} {$protocol}\n"; if (eregi("^HTTP\\/1\\.[1-9]", $protocol)) { $REQUEST .= "Host: {$host}\n"; } $REQUEST .= "User-Agent: {$user_agent}\n"; if ($referer) { $REQUEST .= "Referer: {$referer}\n"; } $REQUEST .= "Connection: close\n"; if ($cookies) { $REQUEST .= $cookies2send; } if ($req_mthd == "POST") { $REQUEST .= "Content-length: " . strlen($content) . "\n"; $REQUEST .= "Content-Type: application/x-www-form-urlencoded\n"; $REQUEST .= "\n{$content}\n"; } fputs($fp, "{$REQUEST}\n"); // complete the request if ($timeout < time()) { return array("content" => ' ', "headers" => ' ', "errcode" => 0, "errmsg" => "Non-Fatal Error: Timed out while downloading page"); } while (!feof($fp) && time() < $timeout) { $output = fgets($fp, 255); $view_output .= $output; if (!isset($header)) { if ($output == "\n" || $output == "\r\n" || $output == "\n\\l") { $header = $view_output; $view_output = ''; } } } } fclose($fp); if (time() > $timeout) { return array("content" => "{$content}", "headers" => "{$headers}", "errcode" => 0, "errmsg" => "Non-Fatal Error: Timed out while downloading page"); } return array("content" => "{$view_output}", "headers" => "{$header}", "errcode" => 1, "errmsg" => "Success"); }
eregi_replace(); import_request_variables(); mcrypt_generic_end(); mysql_db_query(); mysql_escape_string(); mysql_list_dbs(); mysqli_bind_param(); mysqli_bind_result(); mysqli_client_encoding(); mysqli_fetch(); mysqli_param_count(); mysqli_get_metadata(); mysqli_send_long_data(); magic_quotes_runtime(); session_register(); session_unregister(); session_is_registered(); set_magic_quotes_runtime(); set_socket_blocking(); split(); spliti(); sql_regcase(); php_logo_guid(); php_egg_logo_guid(); php_real_logo_guid(); zend_logo_guid(); datefmt_set_timezone_id(); mcrypt_ecb(); mcrypt_cbc(); mcrypt_cfb(); mcrypt_ofb();
function pop3auth() { if ($this->pop3_server == "none") { } else { $fpop = fsockopen($this->pop3_server, $this->pop3_port); if (!$fpop) { echo "ERROR: Could not open socket"; die; } $reply = fgets($fpop, 512); if (!$this->is_ok_pop3($reply)) { echo "Connection ERROR: POP3 server responded with " . $reply; die; } set_socket_blocking($fpop, -1); fwrite($fpop, "USER " . $this->pop3_user . "\r\n"); // Send USER login $reply = fgets($fpop, 512); if (!$this->is_ok_pop3($reply)) { // +OK name is a valid mailbox // -ERR never heard of mailbox name echo "ERROR invalid user or never heard of mailbox name:<br> Response was:" . $reply; fwrite($fpop, "QUIT"); die; } fwrite($fpop, "PASS " . $this->pop3_pass . "\r\n"); // Send user PASS $reply = fgets($fpop, 512); if (!$this->is_ok_pop3($reply)) { // +OK maildrop locked and ready // -ERR invalid password // -ERR unable to lock maildrop echo "POP3 AUTHENTICATION ERROR: invalid password or unable to lock maildrop<br> Response was:" . $reply; fwrite($fpop, "QUIT"); die; } fwrite($fpop, "STAT\r\n"); // Checks mail box $reply = fgets($fpop, 512); fwrite($fpop, "QUIT"); // Quits fclose($fpop); //echo "POP3 Authentication OK<br>"; // Enable this if you want to be told that it worked fine // End POP3 Authentication } }
function sock_set_blocking($socket, $val) { @set_socket_blocking($socket, $val); }
private static function fread($socket, $len) { $buffer = ''; $start_time = time(); set_socket_blocking($socket, 1); while (strlen($buffer) != $len) { if (feof($socket)) { return $buffer; } $r = array(); $n = array(); while (!count($r)) { $r = array($socket); stream_select($r, $n, $n, 10); if (time() - $start_time > 300) { return false; } } $b = fread($socket, $len - strlen($buffer)); if ($b === false) { return false; } $buffer .= $b; if (strlen($buffer) != $len) { } } return $buffer; }
while (list($KEY, $VALUE) = each($SERVER)) { $LOGERRORS = 1; $httpserver = fsockopen("{$VALUE}", 80, &$errno, &$errstr); // Abre a conexao com servidor http if (!$httpserver) { // Se a conexao nao falhar if (isset($LOGERRORS)) { // Se houver qualquer erro declara offline fputs($fpwrite, "<tr>\n"); fputs($fpwrite, "<td>{$link_prefix_off}</td>\n"); fputs($fpwrite, "<td><A HREF=\"http://{$VALUE}\" TARGET=\"{$target}\">{$KEY}</A></td>\n"); fputs($fpwrite, "</tr>\n"); } } else { // Sucesso na conexao, verificar servidor web set_socket_blocking($httpserver, -1); fwrite($httpserver, "get index.html\r\n"); $banner = fgets($httpserver, 128); fclose($httpserver); sleep(1); $file = fopen("http://{$VALUE}/", "r"); if (!$file) { fputs($fpwrite, "<tr>\n"); fputs($fpwrite, "<td>{$link_prefix_off}</td>\n"); fputs($fpwrite, "<td><A HREF=\"http://{$VALUE}\" TARGET=\"{$target}\">{$KEY}</A></td>\n"); fputs($fpwrite, "</tr>"); exit; } fclose($file); fputs($fpwrite, "<tr>\n"); fputs($fpwrite, "<td>{$link_prefix_on}</td>\n");
<?php //php访问Socket $sock = fsockopen('192.168.0.2', 8001, $errno, $errstr, 1); if (!$sock) { echo "{$errstr}({$errno})<br />\n"; } else { set_socket_blocking($sock, false); fwrite($sock, "send data......\r\n"); //数据末尾需要\r\n否则可能无回应,即时刷新也无效,需等关闭连接才有回应 fwrite($sock, "end \r\n"); //end命令终止 while (!feof($sock)) { echo fread($sock, 128); flush(); ob_flush(); sleep(1); } fclose($sock); }