1

Code

function radiotest(host,port)
    local rstr="Online"
    local sock, err = socket.tcp()
    if not sock then
        return "Failed"
    end
    sock:settimeout(1)
    local res, err = sock:connect(host, port)
    if not res then
        return "offline"
    else
        sock:settimeout(1)
        sock:send("GET /index.html HTTP/1.0\r\n UserAgent: SHOUTcast Song Status \r\n Accept: */*\r\n\r\n")
        sock:settimeout(3)
        local data=sock:receive('*a')
        sock:close()
        print(data)
        -- Further processing content here
    end
end
print( radiotest( "10.*.*.*", 1234 ) )

The above socket connection returns me:

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>

I think the problem is in my headers listing, but I'm unable to trace it.

The page opens fine in all browsers(Opera does need to be masked as another browser; otherwise it just keeps on downloading all songs).

I've tried using following strings inside sock:send()

  • GET /index.html HTTP/1.0\r\n UserAgent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\n
  • GET /index.html HTTP/1.0\r\n UserAgent: Opera/9.80 (Windows NT 6.1; Win64; x64) Presto/2.12.388 Version/12.12\r\n\r\n
  • GET /index.html HTTP/1.0\r\n UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17\r\n\r\n

I'm totally stuck at this part. How do I fetch the page using socket.tcp()?

Cœur
  • 37,241
  • 25
  • 195
  • 267
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • 2
    Any reason not to use the http submodule of luasocket rather than raw tcp. http://w3.impa.br/~diego/software/luasocket/http.html – Jane T Feb 15 '13 at 15:52
  • @JaneT I'll merge this with game servers too, using a DLL I already have. – hjpotter92 Feb 15 '13 at 20:00
  • Can you post a packet capture? – Brad Feb 16 '13 at 15:20
  • @Brad If by packet capture, you're referring to the data I receive, then I already have put it in the question. **`ICY 404 Resource Not Found`** This is what I obtain. If it's not what you meant, please tell me how to get the packet trace. – hjpotter92 Feb 16 '13 at 19:51
  • @BackinaFlash, I see what you have posted, but I would rather look at the raw packet capture to see if there is anything strange going on. You can make a capture with Wireshark. http://www.wireshark.org/ – Brad Feb 17 '13 at 05:52
  • @Brad I installed and did a basic reading of Wireshark's manual. Here's the filtered packet result when I run the script: http://www.mediafire.com/?p16ylkertdb9bed My IP is of the form _10.*.*.92_ and the server's IP is _10.*.*.6_. – hjpotter92 Feb 17 '13 at 11:42

2 Answers2

2

After looking at your packet capture, it seems that what is actually getting sent over the wire is wrong. Your user-agent string isn't making it:

> GET /index.html HTTP/1.0

< 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>

If you don't specify a user-agent that contains Mozilla, you will be unable to access the admin interface, or any part of it. Go back and check your code again on what you're sending.

Brad
  • 159,648
  • 54
  • 349
  • 530
0

@Brad Thanks. Your help with Wireshark was indeed practicable. The User-Agent header was not being passed to the server because of an extra space I was providing in the request.

sock:send("GET /index.html HTTP/1.0\r\n UserAgent: SHOUTcast Song Status \r\n Accept: */*\r\n\r\n")

The \r\n UserAgent: SHOUTcast Song Status should instead be:

\r\nUser-Agent: SHOUTcast Song Status

And it is working fine now.

Thanks for the help. :D

The results from the function after filtering out the HTML is like:

Online(Tonic - If You Could Only See)

Online(Tonic - If You Could Only See) Stream is up at 256 kbps with 0 of 32 listeners (0 unique)

Community
  • 1
  • 1
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • Why filter out HTML from the admin interface when you can simply use the XML it provides? – Brad Feb 18 '13 at 03:45
  • @Brad erm, please explain a bit? – hjpotter92 Feb 18 '13 at 03:47
  • I don't remember the URL off the top of my head, but log into your SHOUTcast admin panel, and at the bottom of one of the pages, there is a link for "view XML stats". Just use that URL so you have something consistent to code against, rather than scraping out of the HTML which can/will change in future versions of SHOUTcast. – Brad Feb 18 '13 at 15:21
  • @Brad But I don't have admin privileges on the server. – hjpotter92 Feb 18 '13 at 15:40
  • 1
    Oh, well never mind then. Also, for the version of SHOUTcast you are connecting to, there is `/7.html`. – Brad Feb 18 '13 at 15:56