Old 31st October 2006, 22:20   #1
berth
Junior Member
 
Join Date: Oct 2006
Posts: 7
Unable to retrieve data from DNAS-page

I'm trying to retrieve data from the SHOUTcast D.N.A.S. Status page with php, but it just won't work.
I'm perfectly able to see the page with my browser, but in php it fails to open.
My own work fails as well as all kind of solutions found here or on the web.

One of those solutions found on the web was this:

http://devshed.excudo.net/scripts/ph...houtcast+class

At the bottom of this page you can fill in a host and port for testing and when i fill in here my own host and port it shows up perfectly on that site. (So it is posssible! Very frustrating to know)
But when I use the code i get: Connection refused (111)

I also tried to use Java to retrieve info from the status page, but i get the message:
Quote:
ICY 404 Resource Not Found
icy-notice1:<BR>SHOUTcast Distributed Network Audio Server/win32 v1.9.7<BR>
icy-notice2:The resource requested was not found<BR>
Or a java.net.ConnectException: Connection refused: connect

This is the java code i used:
code:
import java.net.*;
import java.io.*;

public class URLConnectionReader {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://85.146.36.192:8000/index.html");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}



As mentioned above, my ip is 85.146.36.192 and shoutcast is running on port 8000...

Has anyone a proper php code to retrieve the server-information?
berth is offline   Reply With Quote
Old 31st October 2006, 23:01   #2
Sawg
Forum King
 
Join Date: Jun 2000
Location: Phoenix, AZ
Posts: 7,456
Send a message via ICQ to Sawg Send a message via AIM to Sawg Send a message via Yahoo to Sawg
Pass a User-Agent field that begins with Mozilla, otherwise, it will be treated as an audio player

| Brought to you by ^V ^C | The one... the original... no seriously!
Sawg is offline   Reply With Quote
Old 1st November 2006, 05:53   #3
berth
Junior Member
 
Join Date: Oct 2006
Posts: 7
Quote:
Originally posted by Sawg
Pass a User-Agent field that begins with Mozilla, otherwise, it will be treated as an audio player
How do i do that?
Do you've got an code-example?

I would be most gratefull...
berth is offline   Reply With Quote
Old 1st November 2006, 18:09   #4
berth
Junior Member
 
Join Date: Oct 2006
Posts: 7
Quote:
Originally posted by Sawg
Pass a User-Agent field that begins with Mozilla, otherwise, it will be treated as an audio player
I tried to use this script for passing an user-agent:

PHP Code:
<?php
$url 
"85.146.36.192";
$port 8000;
$fp fsockopen($url$port$errno$errstr30);

if( !
$fp ) {
  echo 
"$errstr ($errno)<br />\n";
  echo 
"Cannot retrieve $url";
} else {
  
// send the necessary headers to get the file
  
fputs($fp"GET $path HTTP/1.0\r\n" .
             
"Host: $host\r\n" .
             
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3\r\n" .
             
"Accept: */*\r\n" .
             
"Accept-Language: en-us,en;q=0.5\r\n" .
             
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" .
             
"Keep-Alive: 300\r\n" .
             
"Connection: keep-alive\r\n" .
             
"Referer: [url]http://[/url]$host\r\n\r\n");

  
// retrieve the response from the remote server
  
while ( $line fread$fp4096 ) ) {
     echo 
$line;
  }
  
fclose$fp );
}
?>
But it prints:

Connection refused (111)
Cannot retrieve 85.146.36.192

So it never come's to the part with the useragent-thing, because the
PHP Code:
$fp fsockopen($url$port$errno$errstr30); 
doesn't work...

What am I doing wrong?
berth is offline   Reply With Quote
Old 1st November 2006, 23:35   #5
djSpinnerCee
Forum King
 
djSpinnerCee's Avatar
 
Join Date: Aug 2004
Location: Hollis, Queens/The Bronx, NYC
Posts: 3,555
PHP Code:
fputs($fp"GET $path HTTP/1.0\r\n" 
$path is never initialized... somewhere before fputs() you need $path='/index.html';

or just fix the fputs():
PHP Code:
fputs($fp"GET /index.html HTTP/1.0\r\n" 
There's also some noise that's not necessary and overcomplicates what you're doing. I'll just fix the whole thing and you can compare the difference.

PHP Code:
    fputs($fp"GET /index.html HTTP/1.0\r\n" .
               
"Host: ".$url ":" $port"\r\n" .
               
"User-Agent: Mozilla (PHP)\r\n" .
               
"Connection: Close\r\n\r\n"); 
Your init uses $url, but the script uses $host (it's really just an IP address) -- don't forget to check variable names when you import code from somewhere else.

*add :: I just checked your DNAS - there is no source, but the server is running -- in this "state," listen requests are refused, so if the DNAS does not see the User-Agent header, your script is a listener.
djSpinnerCee is offline   Reply With Quote
Old 2nd November 2006, 06:10   #6
wedtm
Junior Member
 
Join Date: Nov 2006
Location: Denver, CO
Posts: 10
While writing ShoutCONTROL I figured this to be the easiest way of doing things:

PHP Code:
$scp = @fsockopen($data['host'],$data['port'], &$errno, &$errstr30);
         
fputs($scp,"GET /7.html HTTP/1.0\r\nUser-Agent: SC Status (Mozilla Compatible)\r\n\r\n");
         while(!
feof($scp)) {
              
$sc7 .= fgets($scp1024);
             }
@
fclose($scp);
$sc7 ereg_replace(".*<body>"""$sc7);
$sc7 ereg_replace("</body>.*"","$sc7);
$live explode(",",$sc7);
$dummy $sc_contents[0];
$dsp_connected $sc_contents[1];
if(
$i == 0) {
$bgcolor="#999999";

I'm pretty lazy tonight so I didn't format it correctly for you, I just copied it out of our code, but you get the idea, if you call 7.html you get all needed variables that don't need to be parsed, just injected into an array, and then called.

AIM: BMProtocol if you need any more help!
wedtm is offline   Reply With Quote
Old 2nd November 2006, 09:42   #7
berth
Junior Member
 
Join Date: Oct 2006
Posts: 7
Quote:
Your init uses $url, but the script uses $host (it's really just an IP address) -- don't forget to check variable names when you import code from somewhere else.
Okay, there are some copy-paste errors there, but my problem still remains:
When I use:
$scp = @fsockopen($data['host'],$data['port'], &$errno, &$errstr, 30);

or any other code to retrieve data from the server, it fails.
So that fputs-line will never work since $scp (or $fp in the other example) is not properly initialized.


Quote:
*add :: I just checked your DNAS - there is no source, but the server is running -- in this "state," listen requests are refused, so if the DNAS does not see the User-Agent header, your script is a listener.
When I'm testing it is always connected... I leave it connected for testing purposes. Feel free to test!
berth is offline   Reply With Quote
Old 2nd November 2006, 12:44   #8
djSpinnerCee
Forum King
 
djSpinnerCee's Avatar
 
Join Date: Aug 2004
Location: Hollis, Queens/The Bronx, NYC
Posts: 3,555
Maybe something else is wrong:

This link should work for you:

http://85.146.36.192:8000/index.html

Where is the PHP host in relation to the DNAS? and where is the DNAS?

If both are behind a residential broadband router/modem, you may not be able to access the public IP from the LAN, and would have to use the LAN IP of the DNAS server in your PHP.

Most mass-hosted PHP does not allow remote sockets and other file functions because they can expose the underlying hosts files -- fopen() fsockopen(), etc will silently fail.

Regardless, create and upload a simple PHP to your host to get the info you need [name it phpinfo.php] to debug this kind of issue:

PHP Code:
<?php
phpinfo
();
?>
This [returns HTML] will tell you stuff you need to know, especially what modules/features are loaded/enabled, the PHP version, the HTTPd environment, etc.., There should also be a section called disable_functions in "PHP Core" that will tell you what functions are disabled by the server's sysadmin (some even disable phpinfo(), so...).

* suppressing errors and warnings with "@" is hiding information that may also be useful.
djSpinnerCee is offline   Reply With Quote
Old 2nd November 2006, 19:34   #9
berth
Junior Member
 
Join Date: Oct 2006
Posts: 7
thnx for your reply again.

Quote:
Originally posted by djSpinnerCee

This link should work for you:

http://85.146.36.192:8000/index.html
It works in my browser perfectly yes.

Quote:
Where is the PHP host in relation to the DNAS? and where is the DNAS?

If both are behind a residential broadband router/modem, you may not be able to access the public IP from the LAN, and would have to use the LAN IP of the DNAS server in your PHP.
The php host is the place where my website is. ;D Just a hosting company... DNAS is on my pc, ports 8000/8001 are opened. I have a second DNAS server, on a other computer somewhere else. I get the exact same results when trying to retrieve data from that other DNAS server...
I also tried to get the data with Java, that I execute from my own computer.

Quote:
Regardless, create and upload a simple PHP to your host to get the info you need [name it phpinfo.php] to debug this kind of issue
here is the phpinfo:
http://www.flinkfout.nl/phpinfo.php

i believe nothing is disabled..
berth is offline   Reply With Quote
Old 6th November 2006, 21:33   #10
berth
Junior Member
 
Join Date: Oct 2006
Posts: 7
Re: Unable to retrieve data from DNAS-page

Quote:
Originally posted by berth
I'm trying to retrieve data from the SHOUTcast D.N.A.S. Status page with php, but it just won't work.
I'm perfectly able to see the page with my browser, but in php it fails to open.
My own work fails as well as all kind of solutions found here or on the web.

One of those solutions found on the web was this:

http://devshed.excudo.net/scripts/ph...houtcast+class
Ik found out that every other server I fill in doesn't work.
So the problem must be my hosting service?
But why is it that only the fsockopen statement fails with the DNAS-server? Because it is possible for me to use the fsochopen command on other page's like yahoo or something...

And could there a workaround for me to still be able to retrieve data from my DNAS server?
berth is offline   Reply With Quote
Old 6th November 2006, 22:50   #11
djSpinnerCee
Forum King
 
djSpinnerCee's Avatar
 
Join Date: Aug 2004
Location: Hollis, Queens/The Bronx, NYC
Posts: 3,555
Maybe only outbound HTTP on port 80 is allowed by your PHP host, or only connections to certain domain names -- you could try fopen({url}), but read up on it first, it is typically disallowed as well.

At this point you can either set up your own HTTPd at home and run PHP yourself or get the specific details of your hosting with regards to PHP -- beware that many that allow PHP will not allow you to make remote connections because thats exactly how worms are made, and you can get the whole hosting company blacklisted.
djSpinnerCee is offline   Reply With Quote
Old 7th November 2006, 12:52   #12
berth
Junior Member
 
Join Date: Oct 2006
Posts: 7
Excellent! Thanks a lot for your help.

I just changed the port from 8000 to 80 (isn't used anyway) and it works like a charm!

No need to set up a host myself, or contact my hosting company...

Thanks again!
berth is offline   Reply With Quote
Reply
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