一个用于网络的工具函数库

5年以前  |  阅读数:214 次  |  编程语言: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

Query :

<?PHP
}
break;

case "traceroute":
if ($query)
{
print "

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

<FORM ACTION="<?PHP echo($PHP_SELF. "?tool=".$tool); ?>" METHOD="post">
Query :

<?PHP
}
break;

case "whois":
if ($query)
{
print "

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

<FORM ACTION="<?PHP echo($PHP_SELF. "?tool=".$tool); ?>" 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 "
  • <A HREF="".$PHP_SELF."?tool=".$key."">".$val."
  • n";
    }
    print "
n";
break;
}

print "n


".$app_name." v".$app_version."n";
print "n";

?>

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例