Jump to content

Recommended Posts

if ($conn = fsockopen ("whois.internic.net", 43)) {
        fputs($conn, $domain."\r\n");
        while(!feof($conn)) {
            $output .= fgets($conn,128);
        }
        fclose($conn);

 

what those code meaning? how to know what ther result of the $conn. thank you.

the code is form http://www.codesphp.com/php-category/http/php-whois-query-function-to-query-some-nic-databases.html

 

  fputs($conn, $domain."\r\n"); why he write the $domain."\r\n" to $conn

Link to comment
https://forums.phpfreaks.com/topic/246083-what-those-code-meaning/
Share on other sites

The code within the link has a return statement which returns the response from the function. As for what that code is doing, it just opens a socket connection to "whois.internic.net" and writes the domain string (plus a carriage return and new line feed characters) to the stream. Once that data is written, the server at the other end detects the data is sent and responds.

What Adam said.  It looks like it is querying a whois database.  Possibly for some sort of validation. (possibly to ensure the existance of a MX server or such)

 

if ($conn = fsockopen ("whois.internic.net", 43)) // conditional statement.  Attempts to open a socket to the server on port 43, and makes an instance of that connection in the var: $conn
{
        fputs($conn, $domain."\r\n"); // sending data to the server $domain will be pre-assigned.  the "\r\n" are new lines (carriage returns)

        while(!feof($conn)) // while there is still data, the loop will continue until it comes to EOF (end of file)
        {
            $output .= fgets($conn,128); // adds the data sent by the server to a string.
        }
        fclose($conn); // closes the connection.  When the script reaches this point, the server has told us what it knows.  And so it's good practice to close the connection to free resources.
}

 

:)

The code within the link has a return statement which returns the response from the function. As for what that code is doing, it just opens a socket connection to "whois.internic.net" and writes the domain string (plus a carriage return and new line feed characters) to the stream. Once that data is written, the server at the other end detects the data is sent and responds.

what's the purpose of writes the domain string (plus a carriage return and new line feed characters) to the stream? thank you.

What Adam said.  It looks like it is querying a whois database.  Possibly for some sort of validation. (possibly to ensure the existance of a MX server or such)

 

if ($conn = fsockopen ("whois.internic.net", 43)) // conditional statement.  Attempts to open a socket to the server on port 43, and makes an instance of that connection in the var: $conn
{
        fputs($conn, $domain."\r\n"); // sending data to the server $domain will be pre-assigned.  the "\r\n" are new lines (carriage returns)

        while(!feof($conn)) // while there is still data, the loop will continue until it comes to EOF (end of file)
        {
            $output .= fgets($conn,128); // adds the data sent by the server to a string.
        }
        fclose($conn); // closes the connection.  When the script reaches this point, the server has told us what it knows.  And so it's good practice to close the connection to free resources.
}

 

:)

 

many thanks. but there are some points i am still confused.

1, how do i know the port number is 43

 

2, what's the aim of writting the $domain to the $conn

http://www.pc-library.com/ports/tcp-udp-port/43/

 

You're sending data to that server, on port 43, via a socket connection. The fputs function simply handles writing data to that stream; which is the $conn resource. The server is listening for the request on that server, and once you write to it, it writes back a response which is collected using fgets.

What Adam said.  It looks like it is querying a whois database.  Possibly for some sort of validation. (possibly to ensure the existance of a MX server or such)

 

if ($conn = fsockopen ("whois.internic.net", 43)) // conditional statement.  Attempts to open a socket to the server on port 43, and makes an instance of that connection in the var: $conn
{
        fputs($conn, $domain."\r\n"); // sending data to the server $domain will be pre-assigned.  the "\r\n" are new lines (carriage returns)

        while(!feof($conn)) // while there is still data, the loop will continue until it comes to EOF (end of file)
        {
            $output .= fgets($conn,128); // adds the data sent by the server to a string.
        }
        fclose($conn); // closes the connection.  When the script reaches this point, the server has told us what it knows.  And so it's good practice to close the connection to free resources.
}

 

:)

 

many thanks. but there are some points i am still confused.

1, how do i know the port number is 43

 

2, what's the aim of writting the $domain to the $conn

 

1, how do i know the port number is 43

 

With this line:

 

 fsockopen ("whois.internic.net", 43) 

 

Let's break that down a tad.

 

fsockopen is a a built in class that handles new server connections over a port that you tell it to. (http://uk2.php.net/fsockopen)

 

"whois.internic.net" is the domain / ip-address that you want to connect to. (domain being what you type in the URL address bar in your browser.

 

43 is the port.  A port is a virtual doorway to a computer server for data to travel.

 

There is a comma between "whois.internic.net" and the 43.  The reason for this is: you are giving the class another argument alongside the domain. 

 

2, what's the aim of writting the $domain to the $conn

 

$conn is a reference to a resource.  You made that reference when opened the socket.

 

$domain is the domain address you are sending to the whois. (it's called domain to make reading the script easier, for all intensive purposes you could have called it $x and it would have made no difference at all)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.