• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP用于网络的工具函数库

php 搞代码 3年前 (2022-01-23) 22次浏览 已收录 0个评论

PHP用于网络的工具函数库

<?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 “<body>n

“.$tool.” for “.$query.” ..

n”;
} else {
print ““.$app_name.”n”;
print “<body>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 {
?>

” METHOD=”post”>
Server :

Query :

<?PHP
}
break;

case “traceroute”:
if ($query)
{
print “

n”; 
traceroute($query);
print “
“;
} else {
?>

” METHOD=”post”>
Query :

<?PHP
}
break;

case “whois”:
if ($query)
{
print “

n”; 
whois($server,$query);
print “
“;
} else {
?>

<!—ecms


    To look up a NIC handl/本文来源gao@!dai!ma.com搞$$代^@码5网@搞代gaodaima码e, host name, or registrant,
    use one of the keyWords below:

  • To search by NIC handle (or contact), type “handle WA3509”


  • To search by name, type “name lastname, firstname”


  • To search by company name, type “name The Sample Corporation”


  • To search by domain name, type “example.com”


  • To search by ip address, type “host 121.23.2.7”


  • To search by host or nameserver name, type “host ns1.worldnic.com”


  • (examples are from networksolutions.com)
–>

” METHOD=”post”>
This will find .com, .org, and .net domains

Server :

Query :

“>

<?PHP
}
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 “<body>n”;

?>

以上就介绍了PHP用于网络的工具函数库,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP用于网络的工具函数库

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址