Hi,
I'm using the curl functions in php to scrape the wan ip address from my
home router (the router is an SMC product). This is a two step process:
1. post the password value to the login.htm page
2. capture and parse the content from the status_main.htm page
On the SMC's login.htm page there is a form with the following elements:
<form name=tF method=post action=login.ht m>
<input type=password name=pws>
<input type=hidden name=page value=login>
<submit value='LOGIN'>
Here are three test cases - only the first two work as expected. I need to
understand why I got that third response... posting the variables causes a
the SMC to give me a redirection to index.htm which does not exist?
COMMAND LINE TEST (returns login.htm and status_main.htm accurately):
curl -d page=login.htm -d pws=mypassword http://10.10.10.1/login.htm
curl http://10.10.10.1/status_main.htm | grep 'wan_ip'
PHP NO-POST TEST(returns login.htm accurately):
$ch = curl_init("http ://10.10.10.1/login.htm");
$strIP = curl_exec($ch);
curl_close($ch) ;
PHP POST TEST (returns an unexpected result):
$ch = curl_init("http ://10.10.10.1/login.htm");
curl_setopt($ch , CURLOPT_POST, 1);
curl_setopt($ch , CURLOPT_POSTFIE LDS, "page=login&pws =mypassword");
curl_setopt($ch , CURLOPT_RETURNT RANSFER, 1);
$strIP = curl_exec($ch);
curl_close($ch) ;
print "<!-- $strIP -->";
<!-- <html><head><me ta http-equiv=refresh content='0;
url=/index.htm'></head></html> -->
--
TJ Talluto
torpedo51 at yahoo dot com
I'm using the curl functions in php to scrape the wan ip address from my
home router (the router is an SMC product). This is a two step process:
1. post the password value to the login.htm page
2. capture and parse the content from the status_main.htm page
On the SMC's login.htm page there is a form with the following elements:
<form name=tF method=post action=login.ht m>
<input type=password name=pws>
<input type=hidden name=page value=login>
<submit value='LOGIN'>
Here are three test cases - only the first two work as expected. I need to
understand why I got that third response... posting the variables causes a
the SMC to give me a redirection to index.htm which does not exist?
COMMAND LINE TEST (returns login.htm and status_main.htm accurately):
curl -d page=login.htm -d pws=mypassword http://10.10.10.1/login.htm
curl http://10.10.10.1/status_main.htm | grep 'wan_ip'
PHP NO-POST TEST(returns login.htm accurately):
$ch = curl_init("http ://10.10.10.1/login.htm");
$strIP = curl_exec($ch);
curl_close($ch) ;
PHP POST TEST (returns an unexpected result):
$ch = curl_init("http ://10.10.10.1/login.htm");
curl_setopt($ch , CURLOPT_POST, 1);
curl_setopt($ch , CURLOPT_POSTFIE LDS, "page=login&pws =mypassword");
curl_setopt($ch , CURLOPT_RETURNT RANSFER, 1);
$strIP = curl_exec($ch);
curl_close($ch) ;
print "<!-- $strIP -->";
<!-- <html><head><me ta http-equiv=refresh content='0;
url=/index.htm'></head></html> -->
--
TJ Talluto
torpedo51 at yahoo dot com
Comment