Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Technical Support

View Poll Results: Am I Even Close?
Yes 0 0%
No 0 0%
No Clue 1 100.00%
Voters: 1. You may not vote on this poll

Thread Tools Search this Thread Display Modes
Old 26th November 2008, 19:38   #1
Junior Member
Join Date: Oct 2008
Location: Philly
Posts: 6
DNAS: Using cURL for admin.cgi...

I've been trying for 3 friggin' days to get cURL even to gain access to the DNAS streamer thingy. I know nearly nothing about how it works but I have some small understanding of cURL and quite frankly I'm stumped. The majority of my time spent on this was with research of the "curl_setopt(resource,option,value);" method, looking for 'tweaks' that might help me overcome these boundaries.

First, my code...

PHP Code:
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
$scip "myexternalip"// runs on local machine, php host is not local
$scport "8000"// http://localhost:8000 model
$scpass "myadminpass"// sure as hell not giving it to you guys
$url "http://$scip:$scport/admin.cgi";
grabdata() {
$ch curl_init();
curl_setopt ($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20061204 Firefox/");
$odat curl_exec($ch);
$error curl_error($ch);
return array(
$data grabdata();
$data[0] . " --- " $data[1]; 
Overview of what I'm trying to do:

declare a variable as the array returned by the function "grabdata();"

output it.
grabdata (obvious to some) initiates a cURL session, and sets the following options:
-the url (of course)
-printing of verbose information activated
-output to variable as opposed to output buffer (returntransfer)
-make sure each attempt is not taken from a list of cached sessions
-add the username;password extension for the basic auth (later)
-quick server (generally), set 10 second maximum timeout
-set the authentication mode to basic, as admin.cgi asks for the username and password this way through the browser, much like setting the WWW-Authenticate: Basic header in PHP.
-include header information in the gathered data
-a convincing user-agent string
executes the session: put all data into a variable, throw any error information to a variable, output the data to an array.


when I execute this most basic of scripts, I'm just looking for any type of data that would show me that I've gotten a connection to my DNAS...NOPE!!!. The only data ever output is " --- ". No error information, no page information, no headers or raw numeric codes even sent. I understand that most modems or internet routers do not allow connections from your external ip back to your external ip...like say for instance if your ext ip is
and your port is
and your streaming through the DNAS, you can't manually listen to your local stream from your media player by inputting
in most cases you'd have to plug in localhost or or whatever your network is set up to use as the local address.

I don't know if this has anything to do with it. my php host is on a completely separate IP. I've just realized perhaps there's an option to set the port through cURL, I'll try that if there is and adjust accordingly, probably won't help. My options are strict: MUST USE cURL!! If anyone knows how to get even remotely closer to this goal and share it I would be forever grateful.
Deth101 is offline   Reply With Quote
Old 27th November 2008, 04:43   #2
Join Date: Apr 2000
Posts: 4,491
I've used this in the past for curl and it has worked (if $curl is set to 1 then it uses curl otherwise it will try to use fsockopen):

PHP Code:
function streaminfo($ip,$port$message){
$stream = `curl http://$ip:$port/7.html -A \"Mozilla\"`;
$fp =@fsockopen ($ip$port, &$errno, &$errstr2);
"Could not connect to <b>{$ip}:{$port}</b> ({$errno}) - {$errstr}\n";
fputs ($fp"GET /7 HTTP/1.1\r\nUser-Agent:Mozilla\r\n\r\n");
       while (!
$stream fgets($fp,1024);
$stream) = explode("<body>",$stream);
$stream) = explode("</body>",$stream);
$user$status$user_peak$user_max, ,$bitrate$song) = explode(",",$stream);
streaminfo($_GET['ip'], $_GET['port'], $_GET['message']);

You can change the IP and PORT in the function call along with what info to display, right now it is expecting those to be get variables. Also I believe you can still do user:pass@IP:PORT rather than try to pass post variables.

Hope this helps.

Tom is offline   Reply With Quote
Old 27th November 2008, 09:06   #3
Forum King
Join Date: Jul 2004
Location: E*arth
Posts: 3,031
I remember using curl to do this on a godday account
which had a strict php policy after a long time pulling out what little hair i have left,i got it working by setting up port forwarding port 80 - > 8000 on my dnas box and curl using port 80 worked fine.

So Long, and Thanks for All the Fish.
Jkey is offline   Reply With Quote
Old 28th February 2009, 21:16   #4
Join Date: Nov 2008
Posts: 55
Send a message via AIM to kdh
i wrote this nifty perl script, it'll output the viewxml to std out.. might help.

use LWP::UserAgent;
my $ua = LWP::UserAgent->new;

my $response = $ua->get("http://$host:$port/admin.cgi?pass=$pass&mode=viewxml");

if ($response->is_success) {
print $response->decoded_content; # or whatever
else {
die $response->status_line;
kdh is offline   Reply With Quote
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Technical Support

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump