patdavid Posted September 11, 2012 Share Posted September 11, 2012 Hello all, I have a strange question, but a ton of googling and experimenting have led me here as a possible solution to my problem. In a nutshell, I am trying to work around a limitation in using Netflix with XBMC at the moment. If you're not aware, due to a bunch of factors, Netflix in XBMC is called as a browser window separately from the main XBMC program to playback videos (ie: XBMC launches IE to play a video). The problem is that there is no way to use the xbmc ios remote app to control what happens on the netflix window (pause/play/fwd etc...). This is a known problem, and there are a few different solutions that approach it in different ways (but none that work with the app). So I figured I would possibly try my hand at creating a solution on my own. The way the iOS app communicates with xbmc is through HTTP requests to an integrated webserver within xbmc. A specifically crafted HTTP request to the server will cause something to happen in xbmc. What I'd like to try to do is to monitor (in AutoIT, I guess) incoming HTTP requests to my machine, and if I capture a specific request, to then pass an appropriate command to another window (if that window is active). I am having a hard time figuring out how to monitor/sniff network traffic to create this trigger (is it even possible in AutoIT to do this?). Any help or pointers in the right direction would be much appreciated! Link to comment Share on other sites More sharing options...
FireFox Posted September 11, 2012 Share Posted September 11, 2012 Hi, What I'd like to try to do is to monitor (in AutoIT, I guess) incoming HTTP requests to my machine, and if I capture a specific request, Here you go : http://opensource.grisambre.net/pcapau3/ , and if you need help I will show you the right way. to then pass an appropriate command _SendMessage, ControlSend ? if that window is active If WinActive(...) Then Br, FireFox. Link to comment Share on other sites More sharing options...
patdavid Posted September 11, 2012 Author Share Posted September 11, 2012 Holy mackerel that was quick, thanks! This looks like just what I need! I think I can figure out the other portions of my idea (activate the netflix IE window, and sending the correct keys), but the network capture stuff was what had me stumped. Thanks again, and I'll post back if I have any problems (or with some results). Link to comment Share on other sites More sharing options...
FireFox Posted September 11, 2012 Share Posted September 11, 2012 @patdavid I'm glad to help you ! Br, FireFox. Link to comment Share on other sites More sharing options...
patdavid Posted September 14, 2012 Author Share Posted September 14, 2012 So a big thank you @FireFox for the pointer. I've thrown together something that does what I need (a bastardized combination of stuff from the winpcap udf FireFox linked, and some of my own fiddling). I am wondering if things look ok, or if there might be a better way to approach some part of this to make it better/cleaner? expandcollapse popup#include <Winpcap.au3> #include <String.au3> ; These are hex strings from captured packets to the server from iOS remote ; ========================================================================== Local Const $INPUT_LEFT = "496E7075742E4C656674" Local Const $INPUT_RIGHT = "496E7075742E5269676874" Local Const $INPUT_UP = "496E7075742E5570" Local Const $INPUT_DOWN = "496E7075742E446F776E" Local Const $INPUT_SELECT = "496E7075742E53656C656374" Local Const $PLAYER_PLAYPAUSE = "506c617965722e506c61795061757365" Local Const $PLAYER_STOP = "506C617965722E53746F70" ; ========================================================================== while (True) ConsoleWrite(@CRLF & "Waiting for a Netflix window..." & @CRLF) ; Wait for Netflix window to show up $iehandle = WinWait( "http://movies.netflix.com/?" ) ConsoleWrite("The window 'http://movies.netflix.com/?' was opened" & @CRLF) $winpcap=_PcapSetup() ; initialise the Library $pcap_devices=_PcapGetDeviceList() ; Get the interfaces list for which a capture is possible ; Start a capture on interface #0, in promiscuous mode, for tcp packets, port 80 with PSH flag ; This is setup to capture on device #0 right now, change the first index to a different number for a different interface ; [1][0] for device #1... $pcap=_PcapStartCapture($pcap_devices[0][0],"tcp and dst port 80 and tcp[tcpflags] & tcp-push != 0",0) ; Get the PID of the netflix window $iepid = WinGetProcess("http://movies.netflix.com/?") ConsoleWrite("WinActivate: " & WinActivate( $iehandle ) &@CRLF) ; Click in the bottom right corner to truly "activate" the IE window... ConsoleWrite("MouseClick: " & MouseClick( "left", @DesktopWidth, @DesktopHeight/2, 1, 0) & @CRLF) $ieopen = True While ( $ieopen ) ; This should loop based on test for Netflix window? (implement much later!) Sleep( 5 ) ; This makes a huge difference in CPU usage $packet=_PcapGetPacket($pcap) ; Get the packet If IsArray($packet) Then ; Test for input and send/do appropriate actions... $data = string($packet[3]) If stringinstr( $data, $INPUT_LEFT) <> 0 Then ; Captured Input.Left ConsoleWrite("Input.Left" & @CRLF) WinActivate( $iehandle ) Send("+{LEFT}") ; Send Shift+LEFT for continuous seeking ElseIf StringInStr( $data, $INPUT_RIGHT ) <> 0 Then ; Captured Input.Right ConsoleWrite("Input.Right" & @CRLF) WinActivate( $iehandle ) Send("+{RIGHT}") ; Send Shift+RIGHT for continuous seeking ElseIf stringinstr( $data, $PLAYER_PLAYPAUSE ) <> 0 Then ; Captured Player.PlayPause ConsoleWrite("Player.PlayPause" & @CRLF) WinActivate( $iehandle ) send("{SPACE}") ElseIf stringinstr( $data, $INPUT_UP ) <> 0 Then ; Captured Input.Up ConsoleWrite("Input.Up" & @CRLF) WinActivate( $iehandle ) send("{UP}") ElseIf stringinstr( $data, $INPUT_DOWN ) <> 0 Then ; Captured Input.Down ConsoleWrite("Input.Down" & @CRLF) WinActivate( $iehandle ) Send("{DOWN}") ElseIf stringinstr( $data, $PLAYER_STOP ) <> 0 Then ; Captured Player.Stop ConsoleWrite("Player.Stop" & @CRLF) ; This will recursively kill all open iexplore.exe. maybe not the cleanest thing to do... ; Too lazy to track down the window handles or PIDs for iexplore.exe - so just killing them all $iestill = True $i = 1 ConsoleWrite("Trying to kill iexplore.exe..." & @CRLF) While( $iestill ) $pid = ProcessExists("iexplore.exe") ConsoleWrite( "Attempt "& $i & " PID: "& $pid & @CRLF) $i = $i + 1 if ProcessClose( $pid ) == 0 Then $iestill = False Sleep(50) WEnd ; This will kill the IE Netflix window (though there are some weird leftover iexplore.exe floating around) ; I've tried WinKill, WinClose, and ProcessClose - none of them exit cleanly, but this does... ;Run(@ComSpec & " /c taskkill /F /PID " & $iepid & " /T", @SystemDir, @SW_HIDE) ; Too lazy to track down why there's spurious iexplore.exe showing up, so... ; just killing all of them that correspond to http://movies.netflix.com ;~ Local $iewins = WinList( "http://movies.netflix.com" ) ;~ for $i = 1 to $iewins[0][0] ;~ WinKill( $iewins[$i][1] ) ;~ Next $ieopen = False ConsoleWrite("Just finished closing them up..." & @CRLF) EndIf EndIf Wend _PcapStopCapture($pcap) ; Stop capture _PcapFree() ; release resources Sleep(1000) WEnd In checking for a particular string contained in the tcp packet, I figured it would be easier to do a substring match on the hex data as opposed to decoding the packet and testing that way (I think it makes more sense that way?)... Link to comment Share on other sites More sharing options...
FireFox Posted September 14, 2012 Share Posted September 14, 2012 @patdavidThe best way would be to restrict as more as possible the filter, so you can directly set your hex string.I have made a topic for the occasion, where you will have all the infos you need : Br, FireFox. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now