zu simulieren Um meinen Router neu zu starten, kann ich auf die Webseite 192.168.1.1/tools.lp zugreifen und auf die Schaltfläche Restart klicken.PHP So verwenden Sie curl, um Benutzeraktionen auf der Webseite
Dies ist der Code der Seite
<form name="gwRestart" method="post" action="restartingAG.lp">
<input type="hidden" name="action" id="restartAction" value="saveRestart" />
<table border='0' cellspacing='0' cellpadding='0' width='100%' style="text-align:center">
<tr>
<td>
<a href="javascript:document.gwRestart.submit();">
<div class="midarea7-1 mainButton">RESTART</div></a>
</td><td> </td>
</tr>
</table>
</form>
ich meinen Router mit einer PHP-Seite neu starten würde, und ich versuchte es mit Curl auf diese Weise
$post_data['action'] = 'saveRestart';
//traverse array and prepare data for posting (key1=value1)
foreach ($post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$ch = curl_init('http://192.168.1.1/restartingAG.lp');
//set options
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
//set data to be posted
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($ch);
//show information regarding the request
print_r(curl_getinfo($ch));
//echo curl_errno($ch) . '-' . curl_error($ch);
//close the connection
curl_close($ch);
Leider zu tun bemerkte ich, dass Meine Anfrage wird an index_auth.lp umgeleitet (Login-Funktion ist deaktiviert!) und nicht dazu erforderlich.
Array ([url] => http://192.168.1.1/index_auth.lp [content_type] => text/html [http_code] => 200 [header_size] => 858 [request_size] => 630 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 2 [total_time] => 1.216 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 7233 [speed_download] => 5948 [speed_upload] => 0 [download_content_length] => 7233 [upload_content_length] => 0 [starttransfer_time] => 0.53 [redirect_time] => 0.686 [redirect_url] => [primary_ip] => 192.168.1.1 [certinfo] => Array () [primary_port] => 80 [local_ip] => 192.168.1.5 [local_port] => 50687)
Vielleicht weil die Anfrage von einer anderen IP ist? Kann ich irgendwie eine Anfrage stellen, als wäre sie von einem Benutzer auf der Webseite gemacht worden? Danke
die Anfrage von localhost oder Ihrem PC Kommandozeile gemacht wird? Sie müssen zuerst eine Curl-Anfrage machen, um sich zu authentifizieren, und danach eine weitere Curl-Anfrage senden, um den Neustart per Post zu senden – CatalinB
Ich habe versucht sowohl localhost (WAMP), die Befehlszeile über QNAP –
Die Router-Seite erfordert keine Authentifizierung –