: This article mainly introduces the PHP tool function library for the network. if you are interested in the PHP Tutorial, please refer to it. PHP tool library for network
/*
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 "cocould 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 insideOn a html file ..If ($ tool = "listtools "){While (list ($ key, $ val) = each ($ TOOLS )){Print"". $ Val ."N ";}Exit;}// Print appropriate html headerPrint"";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 necessarySwitch ($ 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";?>The above introduces the PHP tool function library for the network, including the content, hope to be helpful to friends who are interested in the PHP Tutorial.