<? 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) <br> 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 "<B> $ a_query is registered at $ a_server: </B> <br> ";
$ 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) <br> N ";
} Else {
Fputs ($ sock, "$ a_queryrn ");
While (! Feof ($ sock ))
{
Echo fgets ($ sock, 128 );
}
Fclose ($ sock );
}
} Else {
Echo "<B> $ a_query was not found. </B> <br> ";
}
}
}
// 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) <br> 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 encoded ded inside <select name = "tool"> On a HTML file ..
If ($ tool = "listtools ")
{
While (List ($ key, $ Val) = each ($ tools )){
Print "<option value =" ". $ key." ">". $ Val. "</option> N ";
}
Exit;
}
// Print appropriate HTML Header
Print "<HTML> ";
If ($ tool)
{
Print "Print "<body> n } Else {
Print "Print "<body> n }
// Check what tool they want to use and do what is necessary
Switch ($ tool ){
Case "finger ":
If ($ query)
{
Print "<PRE> N ";
Finger ($ server, $ query );
Print "</PRE> ";
} Else {
?>
<Form action = "<? PHP echo ($ php_self ."? Tool = ". $ tool);?> "Method =" Post ">
Server: <input type = "text" name = "server" value = "localhost"> <br>
Query: <input type = "text" name = "query" size = "40" maxlength = "100"> <br>
<Input type = "Submit" value = "finger">
</Form>
<? PHP
}
Break;
Case "traceroute ":
If ($ query)
{
Print "<PRE> N ";
Traceroute ($ query );
Print "</PRE> ";
} Else {
?>
<Form action = "<? PHP echo ($ php_self ."? Tool = ". $ tool);?> "Method =" Post ">
Query: <input type = "text" name = "query" size = "40" maxlength = "100"> <br>
<Input type = "Submit" value = "trace route">
</Form>
<? PHP
}
Break;
Case "whois ":
If ($ query)
{
Print "<PRE> N ";
Whois ($ server, $ query );
Print "</PRE> ";
} Else {
?>
<! -- <Ul>
To look up a NIC handle, host name, or registrant,
Use one of the keywords below: <br>
<Li> to search by Nic handle (or contact), type "handle wa3509" </LI> <br>
<Li> to search by name, type "name lastname, firstname" </LI> <br>
<Li> to search by company name, type "Name the sample Corporation" </LI> <br>
<Li> to search by domain name, type "example.com" </LI> <br>
<Li> to search by IP address, type "host 121.23.2.7" </LI> <br>
<Li> to search by host or nameserver name, type "host ns1.worldnic.com" </LI> <br>
(Examples are from networksolutions.com)
</Ul> -->
<Form action = "<? PHP echo ($ php_self ."? Tool = ". $ tool);?> "Method =" Post ">
This will find. com,. org, And. Net domains <br>
Server: <input type = "text" name = "server" value = "rs.internic.net"> <br>
Query: <input type = "text" name = "query" size = "40" maxlength = "100"> <br>
<Input type = "Submit" value = "<? PHP echo $ tools [$ tool];?> ">
</Form>
<? PHP
}
Break;
Default:
Print "<ul> currently supported tools are: N ";
While (List ($ key, $ Val) = each ($ tools )){
Echo "<li> <a href =" ". $ php_self ."? Tool = ". $ key." ">". $ Val. "</a> </LI> N ";
}
Print "</ul> N ";
Break;
}
Print "n <HR> <small>". $ app_name. "v". $ app_version. "</small> N ";
Print "<body> n
?>