Req #66020 [Com]: Can curl_getinfo() return IP address?

From: Date: Sat, 11 Oct 2014 04:28:49 +0000
Subject: Req #66020 [Com]: Can curl_getinfo() return IP address?
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188016@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66020&edit=1

 ID:                 66020
 Comment by:         francois dot bonzon at gmail dot com
 Reported by:        php dot bugs dot ws at jondh dot me dot uk
 Summary:            Can curl_getinfo() return IP address?
 Status:             Open
 Type:               Feature/Change Request
 Package:            cURL related
 Operating System:   OS X
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

This functionality already exists, but is currently not documented. I've sent today a patch to
update the documentation, currently in review.

Use curl_getinfo($ch, CURLINFO_PRIMARY_IP) or look in the "primary_ip" key/value of
curl_getinfo($ch).


Previous Comments:
------------------------------------------------------------------------
[2013-11-02 12:44:33] php dot bugs dot ws at jondh dot me dot uk

Description:
------------
When using the cURL library, some domain names resolve to many IP addresses, but there's no way
(as far as I can tell), in these cases, to see which IP was actually used. I think this would be
useful.

I've discussed this with the author of Guzzle, and he seems to be in agreement that cURL
presently offers no way to do this (see http://stackoverflow.com/a/19599373/472495).

Illustration script attached.

Test script:
---------------
<?php
$host = "www.google.com";

$ips = gethostbynamel($host);
if (count($ips) > 1) {
	echo sprintf("Host %s resolves to these IPs: %s\n", $host, implode(',
', $ips));
} else {
	die(sprintf("Host %s does not resolve to many IPs, so is not a good
example\n", $host));
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$html = curl_exec($ch);
$ok = (bool) $html;
echo $ok ? "Call OK\n" : "Call failed\n";

// Show that there's no way to determine which IP was accessed
echo "Info:\n" . print_r(curl_getinfo($ch), true);

curl_close($ch);


Expected result:
----------------
This is a feature request, so if possible I'd like to see a new key returned by curl_getinfo,
"ip_address", which would be populated with the address used by cURL for the connection.
This would correspond to a new constant CURLINFO_IP_ADDRESS.



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=66020&edit=1


Thread (3 messages)

« previous php.bugs (#188016) next »