I will preface this by saying I’m a Lighting Designer not a programmer so be nice!
I have this API call that I’ve generated from Postman. Short of copy and pasting it over and over, what’s the most effective way to send this call to multiple IPs addresses in a range, factoring in that some IPs might not exist?
i.e. I want to send the below call to every IP from 2.4.7.1 through 2.4.7.99 however 2.4.7.56 may not exist as a device
TIA
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://2.4.7.1/api/profile/10/recall',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"keep_ip_settings": false
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Accept: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
2
Answers
You may put the curl statements in a function (e.g callcurl) so that you can just use a loop to call the function.
The loop can simply be (ignoring 2.4.7.56 by a
if condition
):So the whole code will be: