PHP用於網路的工具函數庫

來源:互聯網
上載者:User
PHP用於網路的工具函數庫


/*
PHP Net Toolpack v0.1 08.05.2000,
by waddler(@netlife.fi)
phpnettoolpack.sourceforge.net
To be distributed under GNU GPL
*/

// whois(hostname [,username, [port]])
Function whois ($a_server, $a_query="", $a_port=43) {
$sock = fsockopen($a_server, $a_port, &$errno, &$errstr, 10);
if (!$sock)
{
echo "$errstr ($errno)
n";
} else {
fputs($sock, "$a_queryrn");
while(!feof($sock))
{
$buf = fgets($sock,128);
if (ereg( "Whois Server:", $buf))
{
$a_server = str_replace( "Whois Server: ", "", $buf);
$a_server = trim($a_server);
}
}
fclose($sock);

if ($a_server)
{
PRint "$a_query is registered at $a_server:
";
$sock = fsockopen($a_server, 43, &$errno, &$errstr, 10);
if(!$sock)
{
echo "Could not open connection to $a_server on port $a_port.n";
echo "$errstr ($errno)
n";
} else {
fputs($sock, "$a_queryrn");
while(!feof($sock))
{
echo fgets($sock,128);
}
fclose($sock);
}
} else {
echo "$a_query was not found.
";
}
}
}


// finger(hostname [,username, [port]])
Function finger ($a_server, $a_query="", $a_port=79) {
$sock=fsockopen($a_server,$a_port, &$errno, &$errstr, 10);
if (!$sock)
{
$ret_str = "$errstr ($errno)
n";
} else {
fputs($sock,"$a_queryn");
while (!feof($sock)) { $ret_str .= fgets($sock,128); }
fclose($sock);
}
echo $ret_str;
return $ret_str;
}


// traceroute(hostname)
Function traceroute ($a_query) {
exec("traceroute $a_query",$ret_strs);
$str_count = count($ret_strs);
for ($count=0; $count < $str_count; $count++)
print "$count/$str_count".$ret_strs[$count]."n";
}


// -----------------------------------------------------------


$app_name = "PHP Net Toolpack";
$app_version = "0.1";

$TOOLS = array(
"finger" => "Finger",
"traceroute" => "Traceroute",
"whois" => "Whois?"
);

// when included inside on a html file .. if ($tool=="listtools") { while (list($key, $val) = each($TOOLS)) { print " ".$val."n"; } exit; } // print appropriate html header print ""; if ($tool) { print "".$tool." for ".$query."n"; print "n".$tool." for ".$query." ..n"; } else { print "".$app_name."n"; print "n".$app_name."n"; } // check what tool they want to use and do what is necessary switch($tool) { case "finger": if ($query) { print "n"; finger($server, $query); print ""; } else { ?> } break; case "traceroute": if ($query) { print "n"; traceroute($query); print ""; } else { ?> } break; case "whois": if ($query) { print "n"; whois($server,$query); print ""; } else { ?> } break; default: print "Currently supported tools are:n"; while (list($key, $val) = each($TOOLS)) { echo "".$val."n"; } print "n"; break; } print "n".$app_name." v".$app_version."n"; print "n"; ?> 以上就介紹了PHP用於網路的工具函數庫,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.