php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33816 gethostbyname() and fsockopen() inconsistant
Submitted: 2005-07-22 11:30 UTC Modified: 2005-07-22 20:21 UTC
From: sey at prometheus-designs dot net Assigned:
Status: Not a bug Package: Network related
PHP Version: 5.0.4 OS: Linux 2.4.29
Private report: No CVE-ID: None
 [2005-07-22 11:30 UTC] sey at prometheus-designs dot net
Description:
------------
I seem to be having inconsistant results using gethostbyname() and fsockopen().  On one hand I can make all the gethostbyname and fsockopen calls I want, as observed in:

http://sey.prometheus-designs.net/meh/index2.php
( Source: http://sey.prometheus-designs.net/meh/index2.phps )

However, in:

http://sey.prometheus-designs.net/meh/index.php
( Source: http://sey.prometheus-designs.net/meh/index.phps )

When one enters a domain in the first text box and nothing in the second, for example, apple.com, my script successfully gets the ip address of whois.verisign-grs.net, but not whois.markmonitor.com.  However, if whois.markmonitor.com is put in the second text box, forcing it to query whois.markmonitor.com first, it runs just fine.

What I believe to be the problematic code is in the get_raw_whois function I made.  Header.php and footer.php are only html with the exception of the date function used in header.php.  Phpinfo is:

http://sey.prometheus-designs.net/phpinfo.php

Reproduce code:
---------------
function get_raw_whois( $whois, $domain )
{
	$ip = gethostbyname( $whois );
	print( 'Attempting to use ' . $whois . ' ( ' . $ip . ' ) ..<br />' );
	
	$fp = fsockopen( $whois, 43, $errno, $errstr, 30 );
	
	if( !$fp )
	{
		$output = 'Could not perform whois: ' . $errno . ' ( ' . $errstr . ' )';
	}
	else 
	{
		fputs( $fp, $domain . "\r\n" );
		
		while( !feof( $fp ) )
		{	
			$temp = trim( fgets( $fp, 1024 ), "\x00..\x1F" );
			
			if( stristr( $temp, 'whois server:' ) )
			{
				fclose( $fp );
				return get_raw_whois( substr( $temp, strpos( $temp, ':' ) + 1 ), $domain );
			}
		
			$output .= $temp . '<br />';
		}
	}
	
	fclose( $fp );
	
	return $output;
}

Expected result:
----------------
$whois is supposed to be a uri to a whois server, $domain a domain name and tld.  First some text is printed about what whois server is being used.  Then a connection is made to that server, if it cannot be contacted in 30 minutes, failure.  Upon successful connection, the whois request is made.  The while statement ensures that all incoming data from the whois request is accounted for in some manner, barring exceptions.  Input is trimmed and then examined to contain 'whois server:'.  If this is found, it grabs that whois server off the end of that line, closes the connection, and recursively runs get_raw_whois, if not, it saves the input in to an output container.  After the whois server is done sending it's stuff, the connection is closed and output is returned to be printed on the screen.

Actual result:
--------------
After the recursive call is made, gethostbyname and fsockopen do not function properly.

Attempting to use whois.verisign-grs.net ( 198.41.3.54 ) ..
Attempting to use whois.markmonitor.com ( whois.markmonitor.com ) ..

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/.camella/sey/sey.prometheus-designs.net/meh/index.php on line 297

Warning: fsockopen() [function.fsockopen]: unable to connect to whois.markmonitor.com:43 (Unknown error) in /home/.camella/sey/sey.prometheus-designs.net/meh/index.php on line 297

Warning: fclose(): supplied argument is not a valid stream resource in /home/.camella/sey/sey.prometheus-designs.net/meh/index.php on line 325
Could not perform whois: -1073765632 ( )

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-22 12:02 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2005-07-22 19:13 UTC] sey at sey dot prometheus-designs dot net
The script is online, at http://sey.prometheus-designs.net/meh/index.phps .. The code segment I put in the 'reproduce code' box was just the function that I thought was messing up, as the rest of the script just formats user input and holds whois server information.  If you need, I can provide another link with a bit shorter version. using just the get_raw_whois function.
 [2005-07-22 19:41 UTC] tony2001@php.net
Please provide a *SHORT* but complete script the clearly shows the problem. "Short" means max. 10-20 lines long. We don't need all those arrays and functions. Just a reproduce script (comments and descriptions are welcome).
Thanks.
 [2005-07-22 20:06 UTC] sey at sey dot prometheus-designs dot net
I'm sorry but all I can get it down to without significantly altering it is 26 lines.  It can be found here:

http://sey.prometheus-designs.net/meh/index3.php
( Source: http://sey.prometheus-designs.net/meh/index3.phps )
 [2005-07-22 20:21 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Please debug your scripts yourself.
trim($whois) helps to remove spaces from the beginning of hostname.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 19:01:25 2019 UTC