I dont like VLC http headers it sends to server
Posted: 26 Jul 2012 00:20
Sorry, probably in wrong place. Didn't really find good place.
Here is server for those who want to play with range attribute http://212.95.32.219:8005
And here is proxy written in autoit for those who want to try out different http headers. This proxy allows you to change http headers into anything you want. Basically $vlc1 gets replaced with $firefox before packet gets forwarded to server.
Red part caused problems with shoutcast. instead of 0 there should be something else. Or Range field could be entirely left out since leaving it out didn't cause any problems to me.GET /;stream.mp3 HTTP/1.1
Host: 127.0.0.1:8005
User-Agent: VLC/2.0.2 LibVLC/2.0.2
Range: bytes=0-
Connection: close
Icy-MetaData: 1
Here is server for those who want to play with range attribute http://212.95.32.219:8005
And here is proxy written in autoit for those who want to try out different http headers. This proxy allows you to change http headers into anything you want. Basically $vlc1 gets replaced with $firefox before packet gets forwarded to server.
Code: Select all
#include <GUIConstantsEx.au3>
#include <Array.au3>
$OriginalUserAgent="VLC/2.0.2 LibVLC/2.0.2"
$NewUserAgent="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0"
$NewUserAgent="VLC/2.0.2 LibVLC/2.0.2"
;~ $firefox = "GET /;stream.mp3 HTTP/1.1" & @CRLF & _
;~ "Host: 127.0.0.1:8005" & @CRLF & _
;~ "User-Agent: "&$NewUserAgent & @CRLF & _
;~ "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & @CRLF & _
;~ "Accept-Language: en-us,en;q=0.5" & @CRLF & _
;~ "Accept-Encoding: gzip, deflate" & @CRLF & _
;~ "Connection: keep-alive" & @CRLF & @CRLF
$firefox = "GET /;stream.mp3 HTTP/1.1" & @CRLF & _
"Host: 127.0.0.1:8005" & @CRLF & _
"User-Agent: "&$NewUserAgent & @CRLF & _
"Range: bytes=1-"& @CRLF & _
"Connection: close" & @CRLF & @CRLF
$vlc1 = "GET /;stream.mp3 HTTP/1.1" & @CRLF & _
"Host: 127.0.0.1:8005" & @CRLF & _
"User-Agent: VLC/2.0.2 LibVLC/2.0.2" & @CRLF
$vlc2 = "GET /;stream.mp3 HTTP/1.1" & @CRLF & _
"Host: 127.0.0.1:8005" & @CRLF & _
"Accept: */*" & @CRLF & _
"User-Agent: NSPlayer/7.10.0.3059" & @CRLF
$szIPADDRESS = "127.0.0.1"
$nPORT = 8005
$remote = "212.95.32.219"
;~ $remote = "194.106.119.241"
;<disable_download>true</disable_download>
$remoteUDP = False
$proxified = False
$remoteTCP = False
$PacketSize = 2014
Dim $MainSocket, $GOOEY, $edit, $LocalTCP, $szIP_Accepted, $msg, $recv
; Start The TCP Services
;==============================================
TCPStartup()
UDPStartup()
$LocalUDP = UDPBind($szIPADDRESS, $nPORT)
; Create a Listening "SOCKET".
; Using your IP Address and Port 33891.
;==============================================
$MainSocket = TCPListen($szIPADDRESS, $nPORT)
; If the Socket creation fails, exit.
If $MainSocket = -1 Then Exit
; Create a GUI for messages
;==============================================
;~ $GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ":" & $nPORT & ")", 640, 480)
;~ $settings = GUICtrlCreateButton("Connections", 0, 0, 80, 19)
;~ $edit = GUICtrlCreateEdit("", 0, 20, 640, 460)
;~ GUISetState()
; Initialize a variable to represent a connection
;==============================================
Dim $LocalTCP[1], $LocalUDP, $remoteTCP[1], $remoteUDP
;Wait for and Accept a connection
;==============================================
Do
$LocalTCP[0] = TCPAccept($MainSocket)
;~ $msg = GUIGetMsg()
;~ If $msg = -3 Then Exit
Until $LocalTCP[0] <> -1
; Get IP of client connecting
$szIP_Accepted = SocketToIP($LocalTCP[0])
; GUI Message Loop
;==============================================
While 1
;~ $msg = GUIGetMsg()
;~ If $msg = -3 Then Exit
$new = TCPAccept($MainSocket)
If $new <> -1 Then
If Not IsArray($LocalTCP) Then
Dim $LocalTCP[1]
$LocalTCP[0] = $new
Else
_ArrayAdd($LocalTCP, $new)
EndIf
If Not IsArray($remoteTCP) Then
Dim $remoteTCP[1]
$remoteTCP[0] = ""
Else
_ArrayAdd($remoteTCP, "")
EndIf
ConsoleWrite("[[TCP local connected]]" & @CRLF)
EndIf
; Try to receive (up to) $PacketSize bytes
;----------------------------------------------------------------
For $i = 0 To UBound($LocalTCP) - 1
;--------------------
If $msg = $GUI_EVENT_CLOSE Then Exit
$TCPl = TCPRecv($LocalTCP[$i], $PacketSize)
If @error Then
TCPCloseSocket($remoteTCP[$i])
TCPCloseSocket($LocalTCP[$i])
ConsoleWrite("[[TCP local Disconnected]]" & @CRLF)
_ArrayDelete($LocalTCP, $i)
_ArrayDelete($remoteTCP, $i)
ExitLoop
EndIf
$UDPl = UDPRecv($LocalUDP, $PacketSize)
If $remoteTCP[$i] Then
$TCPr = TCPRecv($remoteTCP[$i], $PacketSize)
If @error Then
TCPCloseSocket($remoteTCP[$i])
TCPCloseSocket($LocalTCP[$i])
ConsoleWrite("[[TCP Remote Disconnected]]" & @CRLF)
_ArrayDelete($LocalTCP, $i)
_ArrayDelete($remoteTCP, $i)
ExitLoop
EndIf
If $TCPr <> "" Then
_TCPSend($LocalTCP[$i], $TCPr, $i)
EndIf
EndIf
If $remoteUDP Then
$UDPr = UDPRecv($remoteUDP, $PacketSize)
If $UDPr <> "" Then
_UDPSend($LocalUDP, $UDPr)
EndIf
EndIf
;Local TCP,UDP
If $TCPl <> "" Then
If Not $remoteTCP[$i] Then
ConsoleWrite("[[TCP Connected to remote (" & $remote & ")]]" & @CRLF)
$remoteTCP[$i] = TCPConnect($remote, $nPORT)
EndIf
_TCPSend($remoteTCP[$i], $TCPl, $i)
EndIf
If $UDPl <> "" Then
If Not $remoteUDP Then
ConsoleWrite("[[UDP Connected to remote (" & $remote & ")]]" & @CRLF)
$remoteUDP = UDPOpen($remote, $nPORT)
EndIf
_UDPSend($UDPl, $remoteUDP)
EndIf
Next
WEnd
Func _TCPSend($Sock, $send, $i = -1)
$header = StringLeft($send, 6)
If StringLen($send) < 1000 Then
If StringLeft($send, 3) == "GET" Then
If StringInStr($send, $vlc1) Then $send = $firefox;
If StringInStr($send, $vlc2) Then $send = $firefox;
EndIf
ConsoleWrite("Packet: "&$send & @CRLF)
EndIf
TCPSend($Sock, $send)
EndFunc ;==>_TCPSend
Func _UDPSend($Sock, $send)
UDPSend($Sock, $send)
EndFunc ;==>_UDPSend
If $LocalTCP <> -1 Then TCPCloseSocket($LocalTCP)
; Function to return IP Address from a connected socket.
;----------------------------------------------------------------------
Func SocketToIP($SHOCKET)
Local $sockaddr, $aRet
$sockaddr = DllStructCreate("short;ushort;uint;char[8]")
$aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
"ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
If Not @error And $aRet[0] = 0 Then
$aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
If Not @error Then $aRet = $aRet[0]
Else
$aRet = 0
EndIf
$sockaddr = 0
Return $aRet
EndFunc ;==>SocketToIP
;###### NON-PROXY
Func _($_)
$___ = 0
$____ = StringSplit($_, '')
For $__ = 0x01 To StringLen($_)
$___ += Int(StringToBinary($____[$__])) * Int($__)
Next
;~ ConsoleWrite($___&@CRLF)
Return $___
EndFunc ;==>_
Func _IPToString($iIP)
Return Number(BinaryMid($iIP, 1, 1)) & "." & Number(BinaryMid($iIP, 2, 1)) & "." & Number(BinaryMid($iIP, 3, 1)) & "." & Number(BinaryMid($iIP, 4, 1))
EndFunc ;==>_IPToString