电视的网络请求可以从Raspberry Pi的任何设备上运行

时间:2017-11-18 15:53:45

标签: node.js linux curl encoding raspberry-pi

我正试图通过网络控制我的Panasonic电视。当我将它转移到Raspberry时,我从笔记本电脑上运行了所有代码(节点)。出于某种原因,它从那里起作用。 (控制我的Denon接收器的类似项目非常有效。)

“不工作”,我的意思是,可以联系电视,但会返回403错误。当电视关闭时,它无法访问。所以Raspberry呼唤电视。

我尝试了许多不同的方法,最终我正在处理卷曲请求。它适用于所有地方,但不适用于Raspberry:

curl 'http://192.168.178.142:55000/nrc/control_0' \
    -H 'content-type: text/xml; charset="utf-8"' \
    -H 'user-agent: net.thlabs.nodecontrol' \
    -H 'soapaction: "urn:panasonic-com:service:p00NetworkControl:1#X_SendKey"' \
    --data-binary '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:X_SendKey xmlns:u="urn:panasonic-com:service:p00NetworkControl:1"><X_KeyEvent>NRC_MUTE-ONOFF</X_KeyEvent></u:X_SendKey></s:Body></s:Envelope>' \
    --compressed

如果我通过任何其他设备进行代理, 从Raspberry工作我的笔记本电脑。但是,当我从笔记本电脑通过Raspberry进行代理时,它工作。

现在尝试两天,有人有线索吗?

编辑:我进一步减少了卷曲:没有用户代理,内容类型和压缩,这仍然适用于任何笔记本电脑(运行Windows,也尝试过WSL shell),但是在我的覆盆子(1 + 3, Rasbian和ArchLinux),我收到403 。当我另外省略了soapaction时,我到处都收到错误400.

curl 'http://192.168.178.142:55000/nrc/control_0' \
    -H 'soapaction: "urn:panasonic-com:service:p00NetworkControl:1#X_SendKey"' \
    --data-binary '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:X_SendKey xmlns:u="urn:panasonic-com:service:p00NetworkControl:1"><X_KeyEvent>NRC_MUTE-ONOFF</X_KeyEvent></u:X_SendKey></s:Body></s:Envelope>' \
    -w '%{http_code}'

更新1:详细卷曲

笔记本电脑上的

curl -v ...结果:

* Hostname was NOT found in DNS cache
*   Trying 192.168.178.142...
* Connected to 192.168.178.142 (192.168.178.142) port 55000 (#0)
> POST /nrc/control_0 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 192.168.178.142:55000
> Accept: */\*
> soapaction: "urn:panasonic-com:service:p00NetworkControl:1#X_SendKey"
> Content-Length: 314
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 314 out of 314 bytes
< HTTP/1.1 200 OK
< CONTENT-LENGTH: 301
< Content-Type: text/xml; charset="utf-8"
< EXT:
* Server Panasonic-VIErA/1, UPnP/1.0, Panasonic MIL DLNA SERVER is not blacklisted
< SERVER: Panasonic-VIErA/1, UPnP/1.0, Panasonic MIL DLNA SERVER
< CONNECTION: close
<
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
 <s:Body>
   <u:X_SendKeyResponse xmlns:u="urn:panasoniccom:service:p00NetworkControl:1"></u:X_SendKeyResponse>
 </s:Body>
</s:Envelope>
* Closing connection 0
Raspberries上的

curl -v ...结果:

* Hostname was NOT found in DNS cache
*   Trying 192.168.178.142...
* Connected to 192.168.178.142 (192.168.178.142) port 55000 (#0)
> POST /nrc/control_0 HTTP/1.1
> User-Agent: curl/7.38.0
> Host: 192.168.178.142:55000
> Accept: */\*
> soapaction: "urn:panasonic-com:service:p00NetworkControl:1#X_SendKey"
> Content-Length: 314
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 314 out of 314 bytes
< HTTP/1.1 403 Forbidden
< CONNECTION: close
<
* Closing connection 0

更新2:Traceroutes

在Windows笔记本电脑上(Powershell):

tracert 192.168.178.142

Routenverfolgung zu COM-MID1.fritz.box [192.168.178.142] über maximal 30 Hops:

  1     4 ms     3 ms     3 ms  COM-MID1.fritz.box [192.168.178.142]

在Raspberry Pi上:

pi@raspberrypi:~ $ traceroute 192.168.178.142
traceroute to 192.168.178.142 (192.168.178.142), 30 hops max, 60 byte packets
 1  COM-MID1.fritz.box (192.168.178.142)  4.545 ms  4.411 ms  4.347 ms

更新3:Wireshark捕获的HTTP请求

来自笔记本电脑:

0000   c0 d9 62 53 1b 03 00 c2 c6 cd ce 81 08 00 45 00  ..bS..........E.
0010   02 52 00 08 40 00 80 06 12 7f c0 a8 b2 3f c0 a8  .R..@........?..
0020   b2 8e ff 53 d6 d8 9f 96 36 7f e1 55 0f 6c 50 18  ...S....6..U.lP.
0030   fa f0 4d 2d 00 00 50 4f 53 54 20 2f 6e 72 63 2f  ..M-..POST /nrc/
0040   63 6f 6e 74 72 6f 6c 5f 30 20 48 54 54 50 2f 31  control_0 HTTP/1
0050   2e 31 0d 0a 55 73 65 72 2d 41 67 65 6e 74 3a 20  .1..User-Agent: 
0060   63 75 72 6c 2f 37 2e 33 35 2e 30 0d 0a 48 6f 73  curl/7.35.0..Hos
0070   74 3a 20 31 39 32 2e 31 36 38 2e 31 37 38 2e 31  t: 192.168.178.1
0080   34 32 3a 35 35 30 30 30 0d 0a 41 63 63 65 70 74  42:55000..Accept
0090   3a 20 2a 2f 2a 0d 0a 73 6f 61 70 61 63 74 69 6f  : *\*..soapactio
00a0   6e 3a 20 22 75 72 6e 3a 70 61 6e 61 73 6f 6e 69  n: "urn:panasoni
00b0   63 2d 63 6f 6d 3a 73 65 72 76 69 63 65 3a 70 30  c-com:service:p0
00c0   30 4e 65 74 77 6f 72 6b 43 6f 6e 74 72 6f 6c 3a  0NetworkControl:
00d0   31 23 58 5f 53 65 6e 64 4b 65 79 22 0d 0a 43 6f  1#X_SendKey"..Co
00e0   6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 33 31  ntent-Length: 31
00f0   34 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a  4..Content-Type:
0100   20 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 77   application/x-w
0110   77 77 2d 66 6f 72 6d 2d 75 72 6c 65 6e 63 6f 64  ww-form-urlencod
0120   65 64 0d 0a 0d 0a 3c 3f 78 6d 6c 20 76 65 72 73  ed....<?xml vers
0130   69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69  ion="1.0" encodi
0140   6e 67 3d 22 75 74 66 2d 38 22 3f 3e 3c 73 3a 45  ng="utf-8"?><s:E
0150   6e 76 65 6c 6f 70 65 20 78 6d 6c 6e 73 3a 73 3d  nvelope xmlns:s=
0160   22 68 74 74 70 3a 2f 2f 73 63 68 65 6d 61 73 2e  "http://schemas.
0170   78 6d 6c 73 6f 61 70 2e 6f 72 67 2f 73 6f 61 70  xmlsoap.org/soap
0180   2f 65 6e 76 65 6c 6f 70 65 2f 22 20 73 3a 65 6e  /envelope/" s:en
0190   63 6f 64 69 6e 67 53 74 79 6c 65 3d 22 68 74 74  codingStyle="htt
01a0   70 3a 2f 2f 73 63 68 65 6d 61 73 2e 78 6d 6c 73  p://schemas.xmls
01b0   6f 61 70 2e 6f 72 67 2f 73 6f 61 70 2f 65 6e 63  oap.org/soap/enc
01c0   6f 64 69 6e 67 2f 22 3e 3c 73 3a 42 6f 64 79 3e  oding/"><s:Body>
01d0   3c 75 3a 58 5f 53 65 6e 64 4b 65 79 20 78 6d 6c  <u:X_SendKey xml
01e0   6e 73 3a 75 3d 22 75 72 6e 3a 70 61 6e 61 73 6f  ns:u="urn:panaso
01f0   6e 69 63 2d 63 6f 6d 3a 73 65 72 76 69 63 65 3a  nic-com:service:
0200   70 30 30 4e 65 74 77 6f 72 6b 43 6f 6e 74 72 6f  p00NetworkContro
0210   6c 3a 31 22 3e 3c 58 5f 4b 65 79 45 76 65 6e 74  l:1"><X_KeyEvent
0220   3e 4e 52 43 5f 4d 55 54 45 2d 4f 4e 4f 46 46 3c  >NRC_MUTE-ONOFF<
0230   2f 58 5f 4b 65 79 45 76 65 6e 74 3e 3c 2f 75 3a  /X_KeyEvent></u:
0240   58 5f 53 65 6e 64 4b 65 79 3e 3c 2f 73 3a 42 6f  X_SendKey></s:Bo
0250   64 79 3e 3c 2f 73 3a 45 6e 76 65 6c 6f 70 65 3e  dy></s:Envelope>

来自Raspberry:

0000   c0 d9 62 53 1b 03 b8 27 eb fb b4 2f 08 00 45 00  ..bS...'.../..E.
0010   02 5e 7a 2d 40 00 40 06 d8 6f c0 a8 b2 1d c0 a8  .^z-@.@..o......
0020   b2 8e ad e4 d6 d8 af d0 76 fc ef 51 f3 ed 80 18  ........v..Q....
0030   00 e5 6f 0b 00 00 01 01 08 0a 00 09 0c d0 76 94  ..o...........v.
0040   27 05 50 4f 53 54 20 2f 6e 72 63 2f 63 6f 6e 74  '.POST /nrc/cont
0050   72 6f 6c 5f 30 20 48 54 54 50 2f 31 2e 31 0d 0a  rol_0 HTTP/1.1..
0060   55 73 65 72 2d 41 67 65 6e 74 3a 20 63 75 72 6c  User-Agent: curl
0070   2f 37 2e 33 38 2e 30 0d 0a 48 6f 73 74 3a 20 31  /7.38.0..Host: 1
0080   39 32 2e 31 36 38 2e 31 37 38 2e 31 34 32 3a 35  92.168.178.142:5
0090   35 30 30 30 0d 0a 41 63 63 65 70 74 3a 20 2a 2f  5000..Accept: *\
00a0   2a 0d 0a 73 6f 61 70 61 63 74 69 6f 6e 3a 20 22  *..soapaction: "
00b0   75 72 6e 3a 70 61 6e 61 73 6f 6e 69 63 2d 63 6f  urn:panasonic-co
00c0   6d 3a 73 65 72 76 69 63 65 3a 70 30 30 4e 65 74  m:service:p00Net
00d0   77 6f 72 6b 43 6f 6e 74 72 6f 6c 3a 31 23 58 5f  workControl:1#X_
00e0   53 65 6e 64 4b 65 79 22 0d 0a 43 6f 6e 74 65 6e  SendKey"..Conten
00f0   74 2d 4c 65 6e 67 74 68 3a 20 33 31 34 0d 0a 43  t-Length: 314..C
0100   6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 61 70 70  ontent-Type: app
0110   6c 69 63 61 74 69 6f 6e 2f 78 2d 77 77 77 2d 66  lication/x-www-f
0120   6f 72 6d 2d 75 72 6c 65 6e 63 6f 64 65 64 0d 0a  orm-urlencoded..
0130   0d 0a 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d  ..<?xml version=
0140   22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22  "1.0" encoding="
0150   75 74 66 2d 38 22 3f 3e 3c 73 3a 45 6e 76 65 6c  utf-8"?><s:Envel
0160   6f 70 65 20 78 6d 6c 6e 73 3a 73 3d 22 68 74 74  ope xmlns:s="htt
0170   70 3a 2f 2f 73 63 68 65 6d 61 73 2e 78 6d 6c 73  p://schemas.xmls
0180   6f 61 70 2e 6f 72 67 2f 73 6f 61 70 2f 65 6e 76  oap.org/soap/env
0190   65 6c 6f 70 65 2f 22 20 73 3a 65 6e 63 6f 64 69  elope/" s:encodi
01a0   6e 67 53 74 79 6c 65 3d 22 68 74 74 70 3a 2f 2f  ngStyle="http://
01b0   73 63 68 65 6d 61 73 2e 78 6d 6c 73 6f 61 70 2e  schemas.xmlsoap.
01c0   6f 72 67 2f 73 6f 61 70 2f 65 6e 63 6f 64 69 6e  org/soap/encodin
01d0   67 2f 22 3e 3c 73 3a 42 6f 64 79 3e 3c 75 3a 58  g/"><s:Body><u:X
01e0   5f 53 65 6e 64 4b 65 79 20 78 6d 6c 6e 73 3a 75  _SendKey xmlns:u
01f0   3d 22 75 72 6e 3a 70 61 6e 61 73 6f 6e 69 63 2d  ="urn:panasonic-
0200   63 6f 6d 3a 73 65 72 76 69 63 65 3a 70 30 30 4e  com:service:p00N
0210   65 74 77 6f 72 6b 43 6f 6e 74 72 6f 6c 3a 31 22  etworkControl:1"
0220   3e 3c 58 5f 4b 65 79 45 76 65 6e 74 3e 4e 52 43  ><X_KeyEvent>NRC
0230   5f 4d 55 54 45 2d 4f 4e 4f 46 46 3c 2f 58 5f 4b  _MUTE-ONOFF</X_K
0240   65 79 45 76 65 6e 74 3e 3c 2f 75 3a 58 5f 53 65  eyEvent></u:X_Se
0250   6e 64 4b 65 79 3e 3c 2f 73 3a 42 6f 64 79 3e 3c  ndKey></s:Body><
0260   2f 73 3a 45 6e 76 65 6c 6f 70 65 3e              /s:Envelope>

更新4:包含捕获数据包的文件

笔记本电脑:https://drive.google.com/open?id=1P_uVc0ndGG37kizuFBZwApvQ-SePKbZd

RaspPi:https://drive.google.com/open?id=1V4-t3qi5TS8NpYeGqVXLo_zi8PxXbRnp

1 个答案:

答案 0 :(得分:0)

我已通过重置Panasonic TV的出厂参数解决了该问题。但是我不明白问题的根本原因。