How to specify the IP address on curl?
You should be able to use
curl --interface zz.zz.zz.zz http://example.com/
How can I see which IP was used by me on curl?
I'm pretty sure this is not possible, i.e. not in a generic way.
The only way is to have the website report the source IP it sees and send it back as a header / part of the payload, etc. (Basically what the websites suggested in the other answer do)
How to execute the same curl request on a sequence of server IPs (URLs)
You can either use shell's brace expansion in bash
, e.g. {2..15}
for 2,3,4,...,15
:
curl ... http://x.x.x.{2..15}:8080/services/test
or, curl
's alphanumeric series []
operator in the URL part (notice the double-quotes):
curl ... "http://x.x.x.[2-15]:8080/services/test"
Alternatively, you can use arithmetic for
loop:
for ((i=2; i<=15; i++)); do
curl ... "http://x.x.x.$i:8080/services/test"
done
How can I make a CURL request to IP Address PHP?
Try with:
curl_setopt($ch, CURLOPT_URL,"http://127.0.0.1/script.php");
and CURLOPT_POSTFIELDS sould be an array:
$data = array('postdata' => 'postdata', 'postdata1' => 'postdata1');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl always connects to a specific ip:port pair
To be sure what is happening, turn on verbosity with -v
switch:
$ http_proxy=1.2.3.4:8080 curl -v http://google.com
* About to connect() to proxy 1.2.3.4 port 8080 (#0)
* Trying 1.2.3.4...
* Connection timed out
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host
In your case, I'd guess that Curl tries to use proxy. If that is the case, you should check the following:
http_proxy
environment variable:
Check:
env | grep -i proxy
Curl configuration file
~/.curlrc
(unlikely, it doesn't show instrace
)Proxy can be proxided on command line (
-x
or--proxy
), so check ifcurl
isn't aliased in your shell
PHP Curl Not connecting to a url with IP Address and PORT
Using the redacted ip and a slightly modified version of your code as follows:
$url='http://X.XXX.XX.XX:8000/payments/accounts/v1';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 1000,
CURLOPT_CONNECTTIMEOUT => 1000,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POST=>true
)
);
$res=curl_exec( $curl );
curl_close( $curl );
printf('<pre>%s</pre>',print_r( $res, true ));
Yields:
{"detail":"Authentication credentials were not provided."}
Perhaps if you were to actually include and submit some post data in the CURLOPT_POSTFIELDS
option you might find a different response.
Get only the IP Adress in Anaconda Powershell
In Windows PowerShell, curl
does not refer to the external curl.exe
program; instead, it is a built-in alias for PowerShell's Invoke-WebRequest
cmdlet.
In order to invoke curl.exe
, include the filename extension, .exe
:
curl.exe ipinfo.io/ip # Note: The https:// part isn't strictly needed.
Note that this is no longer necessary in PowerShell (Core) v6+, where the curl
alias has been removed, along with others, so as not to shadow external programs that come with the operating system.
Also note that you could also have used the Invoke-RestMethod
cmdlet, which - unlike Invoke-WebRequest
, which returns a wrapper object around the actual data - returns the response data directly (and, as applicable, parses XML data into [xml]
instances and JSON data into [pscustomobject]
instances); its built-in alias is irm
:
irm ipinfo.io/ip # irm == Invoke-RestMethod
As a general tip: To determine which command (a PowerShell-native one or an external program) a given name such as curl
refers to, use the Get-Command
cmdlet.
- By default, the effective command by that name will be listed.
- If you add the
-All
switch, you'll potentially see shadowed command forms.On Windows, if an external program is shadowed, you can still invoke it by excluding the
.exe
extension, as shown.Generally, if a shadowed command is of a different type than the effective command, you can use the
Get-Command
's-Type
parameter to target the shadowed command and invoke it via&
, the call operator; e.g., the (less desirable) alternative to appending.exe
on Windows would be:& (Get-Command -Type Application curl) ipinfo.io/ip
Related Topics
Which Is Fastest in PHP- MySQL or MySQLi
How to Get Jquery Code Completion in Netbeans
Set Character Set Using MySQLi
500 Server Error: Premature End of Script Headers:
Fetching One Row Only with MySQLi
PHP Exec() Not Returning Error Message in Output
Codeigniter Echoing [::1] Instead of Localhost
How to Format Messages for Queueing
Multi-Dimensional Array Post from Form
Detect Mobile Devices - and Tablet Devices
Can PHP Asynchronously Use Sockets
Which Is the Best Character Encoding for Japanese Language for Db, PHP, and HTML Display