Select Outgoing Ip for Curl Request

How to specify the IP address on curl?

You should be able to use

curl --interface zz.zz.zz.zz http://example.com/

cURL with PHP, possible to determine the IP address cURL will use?

You can do this to get your public IP before you call:

$ch = curl_init('http://whatismyip.org/');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
$myIp = curl_exec($ch);

However:

  • If your public IP sometimes changes between cURL sessions, there is nothing to say that it wont change between the above session and the next one for which you actually need this data.
  • It relies on whatismyip.org (or similar service) actually being running.

How to use different IP with curl/wget/file_get_contents?

Because it's not 100% clear from your question:

  • If you need a solution for PHP/cURL, refer to the question Gabi linked to.
  • If you want to do it with CLI curl, do curl --interface INTERFACE
  • If you want to do it with CLI wget, do wget --bind-address=ADDRESS

Edit: To expand on the comment - It is my understanding that an "external IP" is an IP which is not addressable on the current machine. That means that either:

  • ...the interface of the external IP lives on another system and some form of network-fu is happening between the two (or more) systems (like NAT)

    or

  • ...the system you have access to does not grant you access to a local interface by means of the OS and local network stack (network layers can be completely virtualized, for example)

In both cases you obviously can't bind to those interfaces. But to be sure, you will have to get a grasp of your hosters networking setup. If you don't specify an IP, which of the 20 does it use? Is it always the same one?

Change outgoing IP address using Curl

The SOCKS5 protocol itself does not support requesting to bind to a specific IP address. You can see an overview of the SOCKS5 protocol on Wikipedia.

There may be proxy software that supports binding to a specific outgoing IP address based on username. You will have to investigate this yourself.

If using different ports is acceptable, you could request ssh itself to bind to a specific IP address.

ssh -N -b 1.1.1.1 -D 0.0.0.0:1080 localhost
ssh -N -b 1.1.1.2 -D 0.0.0.0:1081 localhost
ssh -N -b 1.1.1.3 -D 0.0.0.0:1082 localhost
...

In summary, it is not possible to achieve this using ssh on its own, you will need to have it bind to multiple IP addresses or ports itself, or investigate other proxy software.

TIdHTTP: Select outgoing IP for HTTP request?

Newer versions of Indy have BoundIP.

idHttp1.BoundIP := '144.33.34.212';

Does cURL open two connections (outgoing and incoming)?

HTTP requires only a single connection to fetch the content of a URL. This is true regardless of whether the program doing the fetch is Curl, Wget, a browser or some other program.

FTP makes two connections to transfer a file. It uses one long-lived connection for "control" activities (logging in, listing directories, requesting a transfer, ...) and makes a second separate connection to perform the actual data transfer. This is a characteristic of the protocol, so again it apples regardless of whether the program is Curl, Wget, a browser or some other program.



Related Topics



Leave a reply



Submit